public IEnumerable <IConfigurationSection> GetChildren(string key)
 {
     return(_configuration.GetChildren());
 }
Beispiel #2
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 public IEnumerable <IConfigurationSection> GetChildren()
 {
     return(Node.GetChildren()
            .Select(it => new CoreConfigurationSection(it)));
 }
        } // End Sub ReadOldSettings

        // https://andrewlock.net/converting-web-config-files-to-appsettings-json-with-a-net-core-global-tool/
        static Newtonsoft.Json.Linq.JObject GetConfigAsJObject(Microsoft.Extensions.Configuration.IConfiguration config)
        {
            Newtonsoft.Json.Linq.JObject root = new Newtonsoft.Json.Linq.JObject();

            foreach (Microsoft.Extensions.Configuration.IConfigurationSection child in config.GetChildren())
            {
                // Not strictly correct, but we'll go with it.
                bool isSection = (child.Value == null);
                if (isSection)
                {
                    // call the function again, passing in the section-children only
                    root.Add(child.Key, GetConfigAsJObject(child));
                }
                else
                {
                    root.Add(child.Key, child.Value);
                }
            } // Next child

            return(root);
        } // End Function GetConfigAsJObject