Exemplo n.º 1
0
        public void SetPathStrings(Hive hive, IEnumerable <string> strings)
        {
            string value = string.Join(";", strings);

            EnvironmentKey access = Access(hive);

            using (var environment = access(writable: true))
            {
                if (environment == null)
                {
                    throw new Error("Failed to open registry key");
                }
                environment.SetValue(Path, value);
                NotifySettingsChange();
            }
        }
Exemplo n.º 2
0
        public IEnumerable <string> GetPathStrings(Hive hive)
        {
            EnvironmentKey access = Access(hive);

            using (var environment = access(writable: false))
            {
                if (environment == null)
                {
                    throw new Error("Failed to open registry key");
                }

                object values = environment.GetValue(Path)
                                ?? "No PATH variable";

                IEnumerable <string> result = values.ToString().Split(';');
                return(result);
            }
        }
Exemplo n.º 3
0
 public static T GetConfigByKey <T>(this EnvironmentKey key, Func <T> getT, Dictionary <EnvironmentKey, dynamic> config = null)
 {
     if (config == null)
     {
         config = Config;
     }
     if (!config.ContainsKey(key))
     {
         config.Add(key, getT());
     }
     if (config[key] == null)
     {
         config[key] = getT();
     }
     try
     {
         return(config[key]);
     }
     catch { }
     return(default(T));
 }
Exemplo n.º 4
0
 public static string?Get(this EnvironmentKey key)
 {
     return(Environment.GetEnvironmentVariable(key.ToString()));
 }
Exemplo n.º 5
0
 public static string GetOrThrow(this EnvironmentKey key)
 {
     return(EnvironmentExtensions.GetOrThrow(key.ToString()));
 }
Exemplo n.º 6
0
 public static bool TryGet(this EnvironmentKey key, [NotNullWhen(true)] out string?value)
 {
     return(EnvironmentExtensions.TryGetEnvironmentVariable(key.ToString(), out value));
 }