public static IEnumerable <EnvironmentVariable> Load(EnvironmentVariableTarget target)
 {
     foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables(target))
     {
         yield return(EnvironmentSerializer.LoadSettings(new EnvironmentVariable(target, entry)));
     }
 }
        public static Boolean Save(IEnumerable <EnvironmentVariable> variables, ref IList <Exception> exceptions)
        {
            Int32 occurrences = 0;

            foreach (EnvironmentVariable variable in variables)
            {
                try
                {
                    if (variable == null || !variable.IsModified)
                    {
                        continue;
                    }

                    if (variable.IsReadonly)
                    {
                        throw new InvalidOperationException("Unable to process read-only variables.");
                    }

                    EnvironmentSerializer.HandleCreated(variable);

                    EnvironmentSerializer.HandleChanged(variable);

                    EnvironmentSerializer.HandleDeleted(variable);
                }
                catch (Exception exception)
                {
                    occurrences++;

                    if (exceptions != null)
                    {
                        exceptions.Add(new EnvironmentException(variable, exception));
                    }

                    Program.Logger.Error("Error while saving environment variables.", exception);
                }
            }

            return(occurrences == 0);
        }