Exemple #1
0
        protected void MapChildrenKeys(HashSet <string> output, IConfigurationSection section, bool deep)
        {
            if (section is MemorySection)
            {
                MemorySection sec = (MemorySection)section;

                foreach (var entry in sec.map)
                {
                    output.Add(CreatePath(section, entry.Key, this));

                    if ((deep) && (entry.Value is IConfigurationSection))
                    {
                        IConfigurationSection subsection = (IConfigurationSection)entry.Value;
                        MapChildrenKeys(output, subsection, deep);
                    }
                }
            }
            else
            {
                HashSet <string> keys = section.GetKeys(deep);

                foreach (string key in keys)
                {
                    output.Add(CreatePath(section, key, this));
                }
            }
        }
Exemple #2
0
        protected void MapChildrenValues(Dictionary <string, object> output, IConfigurationSection section, bool deep)
        {
            if (section is MemorySection)
            {
                MemorySection sec = (MemorySection)section;

                foreach (var entry in sec.map)
                {
                    output.Add(CreatePath(section, entry.Key, this), entry.Value);

                    var value = entry.Value as IConfigurationSection;
                    if (value != null)
                    {
                        if (deep)
                        {
                            MapChildrenValues(output, value, true);
                        }
                    }
                }
            }
            else
            {
                Dictionary <string, object> values = section.GetValues(deep);

                foreach (var entry in values)
                {
                    output.Add(CreatePath(section, entry.Key, this), entry.Value);
                }
            }
        }
Exemple #3
0
        public IConfigurationSection CreateSection(string path)
        {
            Debug.Assert(!string.IsNullOrEmpty(path), "Cannot create section at empty path");
            IConfiguration root = GetRoot();

            if (root == null)
            {
                throw new Exception("Cannot create section without a root");
            }

            char separator = root.Options().PathSeparator();
            // i1 is the leading (higher) index
            // i2 is the trailing (lower) index
            int i1 = -1, i2;
            IConfigurationSection section = this;

            while ((i1 = path.IndexOf(separator, i2 = i1 + 1)) != -1)
            {
                String node = path.Substring(i2, i1);
                IConfigurationSection subSection = section.GetConfigurationSection(node);
                if (subSection == null)
                {
                    section = section.CreateSection(node);
                }
                else
                {
                    section = subSection;
                }
            }

            String key = path.Substring(i2);

            if (section == this)
            {
                IConfigurationSection result = new MemorySection(this, key);
                map.Add(key, result);
                return(result);
            }
            return(section.CreateSection(key));
        }