Example #1
0
 internal void Initialize()
 {
     if (ConfigSectionsOrGroups != null)
     {
         foreach (object element in ConfigSectionsOrGroups)
         {
             if (element is ChoConfigurationSection)
             {
                 if (!((ChoConfigurationSection)element).Name.IsNullOrWhiteSpace())
                 {
                     _sectionsDict.Add(((ChoConfigurationSection)element).Name, element as ChoConfigurationSection);
                 }
             }
             else if (element is ChoConfigurationSectionGroup)
             {
                 ChoConfigurationSectionGroup configurationSectionGroup = element as ChoConfigurationSectionGroup;
                 if (!configurationSectionGroup.Name.IsNullOrWhiteSpace())
                 {
                     configurationSectionGroup.Initialize();
                     _sectionGroupsDict.Add(configurationSectionGroup.Name, configurationSectionGroup);
                 }
             }
         }
     }
 }
Example #2
0
        private static bool ContainSection(string sectionName, ChoConfigurationSectionGroup sectionGroup)
        {
            if (_configuration == null)
            {
                return(true);
            }

            int index = sectionName.IndexOf('/');

            if (index >= 0)
            {
                string sectionGroupName = sectionName.Substring(0, index).Trim();
                if (String.IsNullOrEmpty(sectionGroupName))
                {
                    return(false);
                }

                sectionGroup = sectionGroup == null ? _configuration.SectionGroups[sectionGroupName] : sectionGroup.SectionGroups[sectionGroupName];
                if (sectionGroup == null)
                {
                    return(false);
                }

                return(ContainSection(sectionName.Substring(index + 1), sectionGroup));
            }
            else
            {
                return(sectionGroup.Sections[sectionName] != null);
            }
        }
Example #3
0
 internal void Initialize()
 {
     if (ConfigSection != null)
     {
         ConfigSection.Initialize();
     }
     else
     {
         ConfigSection = new ChoConfigurationSectionGroup();
     }
 }
Example #4
0
        private static ChoConfigurationSection GetConfigSection(string sectionName, ChoConfigurationSectionGroup sectionGroup)
        {
            if (sectionName.IsNullOrEmpty())
            {
                return(null);
            }

            sectionName = sectionName.Trim();

            int pos = sectionName.IndexOf('/');

            if (pos >= 0)
            {
                string sectionGroupName = sectionName.Substring(0, pos);
                sectionName = sectionName.Substring(pos + 1, sectionName.Length - (pos + 1));

                if (sectionGroupName.IsNullOrEmpty())
                {
                    return(GetConfigSection(sectionName, sectionGroup));
                }
                else
                {
                    if (sectionGroup == null)
                    {
                        if (_configuration.SectionGroups.ContainsKey(sectionGroupName))
                        {
                            sectionGroup = _configuration.SectionGroups[sectionGroupName];
                        }
                    }
                    else
                    {
                        if (sectionGroup.SectionGroups.ContainsKey(sectionGroupName))
                        {
                            sectionGroup = sectionGroup.SectionGroups[sectionGroupName];
                        }
                    }

                    if (sectionGroup == null)
                    {
                        return(null);
                    }

                    return(GetConfigSection(sectionName, sectionGroup));
                }
            }
            else
            {
                if (sectionGroup == null)
                {
                    if (_configuration.Sections.ContainsKey(sectionName))
                    {
                        return(_configuration.Sections[sectionName]);
                    }
                    else
                    {
                        return(null);
                    }
                }
                else
                {
                    if (sectionGroup.Sections.ContainsKey(sectionName))
                    {
                        return(sectionGroup.Sections[sectionName]);
                    }
                    else
                    {
                        return(null);
                    }
                }

                //return sectionGroup == null ? _configuration.Sections[sectionName] : sectionGroup.Sections[sectionName];
            }
        }