This commit is contained in:
commit
5a825ffab2
52 changed files with 3780 additions and 0 deletions
43
src/Process/Builders/EnvironmentVariablesBuilder.cs
Normal file
43
src/Process/Builders/EnvironmentVariablesBuilder.cs
Normal file
|
@ -0,0 +1,43 @@
|
|||
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);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue