dotnetCampus.Configurations icon indicating copy to clipboard operation
dotnetCampus.Configurations copied to clipboard

定义配置类的方式下,能否在配置文件中指定不同的前缀?

Open asuper0 opened this issue 1 year ago • 4 comments

比如现在配置类定义这样

internal class StateConfiguration : Configuration
{
    /// <summary>
    /// 获取或设置整型。
    /// </summary>
    internal int? Count
    {
        get => GetInt32();
        set => SetValue(value);
    }

    /// <summary>
    /// 获取或设置带默认值的整型。
    /// </summary>
    internal int Length
    {
        get => GetInt32() ?? 2;
        set => SetValue(Equals(value, 2) ? null : value);
    }
}

那么配置文件是长这样

> 配置文件
> 版本 1.0
StateConfiguration.Count
0
>
StateConfiguration.Length
2
>
> 配置文件结束

有没有办法让StateConfiguration.Count的前缀StateConfiguration,可以出现多种?

asuper0 avatar Jun 24 '24 07:06 asuper0

@asuper0 试试写构造函数?构造函数的 base 传入字符串

lindexi avatar Jun 25 '24 12:06 lindexi

没懂,能举例说一下吗,我是想要一个配置文件中定义多种前缀

asuper0 avatar Jun 28 '24 02:06 asuper0

@asuper0 那就多个配置项的类试试

lindexi avatar Jun 28 '24 02:06 lindexi

@asuper0 或者是配置类的基础构造函数传入空字符串,然后在每个属性的 Set 和 Get 里面自己传入字符串

lindexi avatar Jun 28 '24 02:06 lindexi