zhaolei
6 days ago 921de2254ff5712a44ed8575ee8efe34252f6603
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
32
33
34
35
36
37
38
39
#if !NET45
using Microsoft.Extensions.Logging;
using System;
using System.Reflection;
 
namespace Prow.Configuration
{
    /// <summary>
    /// 配置项操作类
    /// </summary>
    internal static class ConfigurationOptionsAliasUtilities
    {
        private const string AliasAttibuteAliasProperty = "Alias";
 
        /// <summary>
        /// 通过类型获取配置项键值方法
        /// </summary>
        /// <param name="providerType"></param>
        /// <returns></returns>
        public static string GetAlias(Type providerType)
        {
            string? ret = null;
            foreach (var attribute in providerType.GetTypeInfo().GetCustomAttributes(false))
            {
                if (attribute.GetType().FullName == typeof(ProviderAliasAttribute).FullName)
                {
                    var valueProperty = attribute
                        .GetType()
                        .GetProperty(AliasAttibuteAliasProperty, BindingFlags.Public | BindingFlags.Instance);
 
                    ret = valueProperty?.GetValue(attribute) as string;
                    break;
                }
            }
            return ret ?? string.Empty;
        }
    }
}
#endif