How to read values from config.json in Console Application

后端 未结 4 2208
南旧
南旧 2021-02-15 08:54

I just installed ASP.NET 5 and created a Console Application in Visual Studio. I\'ve added a file, config.json, to the root folder of the project.

It looks like this:

4条回答
  •  走了就别回头了
    2021-02-15 09:46

    Have a type like the following:

    public class FolderSettings
    {
        public Dictionary TargetFolderLocations { get; set; }
    }
    

    You can then use the ConfigurationBinder to automatically bind configuration sections to types like above. Example:

    var folderSettings = ConfigurationBinder.Bind(config.GetConfigurationSection("Data"));
    var path = folderSettings.TargetFolderLocations["TestFolder1"];
    

提交回复
热议问题