ps:废话不多说。直接上代码:源码地址:https://github.com/786744873/Asp.Net-Core-2.1-All-Demos/tree/master/src

Configuration的配置

说明:基于三种方式的读取配置文件以及自定义读取自定义配置文件

文件结构

ASP.NET Core 2.1的配置、AOP、缓存、部署、ORM、进程守护、Nginx、Polly【源码】

代码

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;
    }
}
View Code

相关文章:

  • 2021-08-16
  • 2022-01-05
  • 2021-11-26
  • 2021-11-02
  • 2018-07-12
  • 2018-07-05
猜你喜欢
  • 2021-08-16
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
相关资源
相似解决方案