|
|
1 день назад | |
|---|---|---|
| .. | ||
| Apq.Cfg.Ini.csproj | 2 дней назад | |
| CfgBuilderExtensions.cs | 6 дней назад | |
| IniFileCfgSource.cs | 1 день назад | |
| README.md | 1 день назад | |
INI 文件配置源扩展包。
仓库地址:https://gitee.com/apq/Apq.Cfg
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 |
是否为默认写入目标 |
; 根级别配置
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