43 lines
No EOL
1.2 KiB
C#
43 lines
No EOL
1.2 KiB
C#
namespace Geekeey.Extensions.Process;
|
|
|
|
/// <summary>
|
|
/// Builder that helps configure environment variables.
|
|
/// </summary>
|
|
public sealed class EnvironmentVariablesBuilder
|
|
{
|
|
private readonly Dictionary<string, string?> _vars = new(StringComparer.Ordinal);
|
|
|
|
/// <summary>
|
|
/// Sets an environment variable with the specified name to the specified value.
|
|
/// </summary>
|
|
public EnvironmentVariablesBuilder Set(string name, string? value)
|
|
{
|
|
_vars[name] = value;
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets multiple environment variables from the specified sequence of key-value pairs.
|
|
/// </summary>
|
|
public EnvironmentVariablesBuilder Set(IEnumerable<KeyValuePair<string, string?>> variables)
|
|
{
|
|
foreach (var (name, value) in variables)
|
|
{
|
|
Set(name, value);
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Sets multiple environment variables from the specified dictionary.
|
|
/// </summary>
|
|
public EnvironmentVariablesBuilder Set(IReadOnlyDictionary<string, string?> variables)
|
|
=> Set((IEnumerable<KeyValuePair<string, string?>>)variables);
|
|
|
|
/// <summary>
|
|
/// Builds the resulting environment variables.
|
|
/// </summary>
|
|
public IReadOnlyDictionary<string, string?> Build()
|
|
=> new Dictionary<string, string?>(_vars, _vars.Comparer);
|
|
} |