-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCPluginEnvConfiguration.cs
38 lines (32 loc) · 1.18 KB
/
CPluginEnvConfiguration.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System;
using System.Collections.Generic;
using System.Linq;
namespace CPlugin.Net;
/// <summary>
/// Represents a configuration to get the plugin files from an environment variable.
/// </summary>
/// <remarks>
/// The variable must be called <c>PLUGINS</c> and its value must be a string separated by spaces or new lines.
/// <para>Example:</para>
/// <c>PLUGINS=MyPlugin1.dll MyPlugin2.dll</c>
/// </remarks>
public class CPluginEnvConfiguration : CPluginConfigurationBase
{
private static readonly string[] s_separator = [" ", "\t", "\r\n", "\n", "\r"];
/// <summary>
/// Initializes a new instance of the <see cref="CPluginEnvConfiguration"/> class.
/// </summary>
public CPluginEnvConfiguration() { }
/// <inheritdoc />
public override IEnumerable<string> GetPluginFiles()
{
var retrievedValue = Environment.GetEnvironmentVariable("PLUGINS");
if(retrievedValue is null)
return [];
var pluginFiles = retrievedValue
.Split(s_separator, StringSplitOptions.None)
.Where(pluginFile => !string.IsNullOrWhiteSpace(pluginFile))
.Select(GetPluginPath);
return pluginFiles;
}
}