黄中银 622499f87b 编码处理流程文档 1 день назад
..
Apq.Cfg.Ini.csproj 886770f7be NuGet中的README内容可在发布时定制 2 дней назад
CfgBuilderExtensions.cs 670ed78c73 0.0.1 6 дней назад
IniFileCfgSource.cs 622499f87b 编码处理流程文档 1 день назад
README.md 825e944450 依赖注入支持 1 день назад

README.md

Apq.Cfg.Ini

Gitee

INI 文件配置源扩展包。

仓库地址https://gitee.com/apq/Apq.Cfg

依赖

  • Apq.Cfg
  • Microsoft.Extensions.Configuration.Ini(版本随目标框架:net6.0→6.0.0, net7.0→7.0.0, net8.0→8.0.0, net9.0→9.0.0)

用法

using Apq.Cfg;
using Apq.Cfg.Ini;

var cfg = new CfgBuilder()
    .AddIni("config.ini", level: 0, writeable: true)
    .Build();

// 使用配置节访问
var dbSection = cfg.GetSection("Database");
var connStr = dbSection.Get("ConnectionString");

// 枚举子键
foreach (var key in dbSection.GetChildKeys())
{
    Console.WriteLine($"{key}: {dbSection.Get(key)}");
}

方法签名

public static CfgBuilder AddIni(
    this CfgBuilder builder,
    string path,
    int level,
    bool writeable = false,
    bool optional = true,
    bool reloadOnChange = true,
    bool isPrimaryWriter = false)

参数说明

参数 说明
path INI 文件路径
level 配置层级,数值越大优先级越高
writeable 是否可写
optional 文件不存在时是否忽略
reloadOnChange 文件变更时是否自动重载
isPrimaryWriter 是否为默认写入目标

INI 格式示例

; 根级别配置
AppName=MyApp

[Database]
ConnectionString=Server=localhost;Database=mydb
Timeout=30

[Logging]
Level=Information

配置键映射:

  • AppName -> "AppName"
  • Database:ConnectionString -> "Database:ConnectionString"
  • Logging:Level -> "Logging:Level"

许可证

MIT License

作者

仓库