增加JsonConfigProvider.LoadAppSettings的单元测试
大石头 authored at 2022-10-07 10:15:39 智能大石头 committed at 2022-12-25 19:35:54
1.49 KiB
X
namespace NewLife.Configuration;

/// <summary>配置对象</summary>
public interface IConfigSection
{
    /// <summary>配置名</summary>
    String Key { get; set; }

    /// <summary>配置值</summary>
    String Value { get; set; }

    /// <summary>注释</summary>
    String Comment { get; set; }

    /// <summary>子级</summary>
    IList<IConfigSection> Childs { get; set; }

    /// <summary>获取 或 设置 配置值</summary>
    /// <param name="key">配置名,支持冒号分隔的多级名称</param>
    /// <returns></returns>
    String this[String key] { get; set; }
}

/// <summary>配置项</summary>
public class ConfigSection : IConfigSection
{
    #region 属性
    /// <summary>配置名</summary>
    public String Key { get; set; }

    /// <summary>配置值</summary>
    public String Value { get; set; }

    /// <summary>注释</summary>
    public String Comment { get; set; }

    /// <summary>子级</summary>
    public IList<IConfigSection> Childs { get; set; }
    #endregion

    #region 方法
    /// <summary>获取 或 设置 配置值</summary>
    /// <param name="key">键</param>
    /// <returns></returns>
    public virtual String this[String key]
    {
        get => this.Find(key, false)?.Value;
        set => this.Find(key, true).Value = value;
    }

    /// <summary>已重载。</summary>
    /// <returns></returns>
    public override String ToString() => Childs != null && Childs.Count > 0 ? $"{Key}[{Childs.Count}]" : $"{Key}={Value}";
    #endregion
}