diff --git a/Bonsai.System/IO/GetEnvironmentVariable.cs b/Bonsai.System/IO/GetEnvironmentVariable.cs new file mode 100644 index 000000000..ba423227e --- /dev/null +++ b/Bonsai.System/IO/GetEnvironmentVariable.cs @@ -0,0 +1,51 @@ +using System; +using System.ComponentModel; +using System.Reactive.Linq; + +namespace Bonsai.IO +{ + /// + /// Represents an operator that gets the value of an environment variable for the current process. + /// + [Description("Returns the value of an environment variable for the current process.")] + public class GetEnvironmentVariable : Source + { + /// + /// Gets or sets the name of the environment variable to query the value of. + /// + [Description("The name of the environment variable to query the value of.")] + public string Name { get; set; } + + /// + /// Gets the value of the specified environment variable for the current process + /// and returns it through an observable sequence. + /// + /// + /// A sequence containing the value of the specified environment variable. The + /// value will be if the environment variable is not found. + /// + public override IObservable Generate() + { + return Observable.Return(Environment.GetEnvironmentVariable(Name)); + } + + /// + /// Gets the value of the specified environment variable for the current process + /// whenever an observable sequence emits a notification. + /// + /// + /// The type of the elements in the sequence. + /// + /// + /// The sequence of notifications used to get the value of the environment variable. + /// + /// + /// A sequence containing the current values of the specified environment variable. + /// The value may be if the environment variable is not found. + /// + public IObservable Generate(IObservable source) + { + return source.Select(_ => Environment.GetEnvironmentVariable(Name)); + } + } +}