Apq.Cfg.ICfgSection.Get.md 2.0 KB

Apq.Cfg

Apq.Cfg.ICfgSection

ICfgSection.Get Method

Overloads
Get(string) 获取配置值(相对于此节的键)
Get<T>(string) 获取配置值并转换为指定类型

ICfgSection.Get(string) Method

获取配置值(相对于此节的键)

string? Get(string key);

Parameters

key System.String

相对于此节的键名

Returns

System.String
配置值,不存在时返回null

Example

var dbSection = cfg.GetSection("Database");
var host = dbSection.Get("Host"); // 等同于 cfg.Get("Database:Host")

ICfgSection.Get<T>(string) Method

获取配置值并转换为指定类型

T? Get<T>(string key);

Type parameters

T

目标类型

Parameters

key System.String

相对于此节的键名

Returns

T
转换后的配置值,不存在或转换失败时返回默认值

Example

var dbSection = cfg.GetSection("Database");
var port = dbSection.Get<int>("Port"); // 等同于 cfg.Get<int>("Database:Port")