Esempio 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();
            }
        }
Esempio 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);
            }
        }
Esempio 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));
 }
Esempio n. 4
0
 public static string?Get(this EnvironmentKey key)
 {
     return(Environment.GetEnvironmentVariable(key.ToString()));
 }
Esempio n. 5
0
 public static string GetOrThrow(this EnvironmentKey key)
 {
     return(EnvironmentExtensions.GetOrThrow(key.ToString()));
 }
Esempio n. 6
0
 public static bool TryGet(this EnvironmentKey key, [NotNullWhen(true)] out string?value)
 {
     return(EnvironmentExtensions.TryGetEnvironmentVariable(key.ToString(), out value));
 }