ps:废话不多说。直接上代码:源码地址:https://github.com/786744873/Asp.Net-Core-2.1-All-Demos/tree/master/src
Configuration的配置
说明:基于三种方式的读取配置文件以及自定义读取自定义配置文件
文件结构
代码
PropertiesConfigurationProvider.cs
public class PropertiesConfigurationProvider:ConfigurationProvider { string _path = string.Empty; public PropertiesConfigurationProvider(string path) { this._path = path; } /// <summary> /// 用于解析1.properties /// </summary> public override void Load() { var lines = File.ReadAllLines(this._path); var dict = new Dictionary<string, string>(); foreach (var line in lines) { var items = line.Split('='); dict.Add(items[0], items[1]); } this.Data = dict; } }