zhaolei
9 days ago 4a2e5b9a21940f11757be37d99f0944e240e908b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#if !NET45
using Prow.Configuration;
 
namespace Microsoft.Extensions.Configuration
{
    /// <summary>
    /// 配置文件配置小节映射操作类
    /// </summary>
    public static class ConfigurationExtensions
    {
        /// <summary>
        /// 通过类型获得配置小节 读取顺序 Key > Name > FullName > ProviderAlias
        /// </summary>
        /// <param name="configuration"></param>
        /// <returns></returns>
        public static IConfigurationSection GetSection<T>(this IConfiguration configuration)
        {
            var providerType = typeof(T);
            var section = configuration.GetSection(providerType.Name);
            if (!section.Exists()) section = configuration.GetSection(providerType.FullName);
 
            if (!section.Exists())
            {
                var alias = ConfigurationOptionsAliasUtilities.GetAlias(providerType);
                if (!string.IsNullOrEmpty(alias)) section = configuration.GetSection(alias);
            }
            return section;
        }
    }
}
#endif