Пример #1
0
        private static Dictionary <string, string> GetSettingsValues(
            SystemConfiguration configuration,
            ConfigurationSectionPath sectionPath,
            ICollection <PropertyInfo> properties)
        {
            var values = new Dictionary <string, string>();

            if (properties.Count > 0)
            {
                var section = sectionPath.GetSection(configuration);
                if (section != null)
                {
                    var clientSection = CastToClientSection(section);
                    foreach (PropertyInfo property in properties)
                    {
                        SettingElement element = GetSettingElement(clientSection, property, false);
                        if (element != null)                         //If the setting element is there, we'll assume it means the value is to be set.
                        {
                            values[property.Name] = GetElementValue(element);
                        }
                    }
                }
            }

            return(values);
        }
Пример #2
0
        private static bool UpdateSection(SystemConfiguration configuration, ConfigurationSectionPath sectionPath, IEnumerable <PropertyInfo> properties, IDictionary <string, string> newValues)
        {
            var section = sectionPath.GetSection(configuration);

            if (section != null)
            {
                return(UpdateSection(CastToClientSection(section), properties, newValues));
            }

            var group = sectionPath.GroupPath.GetSectionGroup(configuration, true);

            section = sectionPath.CreateSection();

            if (!UpdateSection(CastToClientSection(section), properties, newValues))
            {
                return(false);
            }

            group.Sections.Add(sectionPath.SectionName, section);
            return(true);
        }