Class CfgSectionAttribute
标记一个类为配置节,源生成器将为其生成零反射的绑定代码
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
public sealed class CfgSectionAttribute : Attribute
- Inheritance
-
CfgSectionAttribute
- Inherited Members
Remarks
使用示例:
[CfgSection("Database")]
public partial class DatabaseConfig
{
public string ConnectionString { get; set; }
public int Timeout { get; set; } = 30;
}
// 使用生成的绑定方法
var config = DatabaseConfig.BindFrom(cfg.GetSection("Database"));
Constructors
CfgSectionAttribute(string)
创建配置节特性
public CfgSectionAttribute(string sectionPath = "")
Parameters
sectionPathstring配置节路径,为空时使用类名(去掉 Config/Settings 后缀)
Properties
GenerateExtension
是否生成扩展方法,默认为 true
public bool GenerateExtension { get; set; }
Property Value
SectionPath
配置节路径,如 "Database" 或 "App:Settings"
public string SectionPath { get; }