public void TestSetProperty()
 {
     var test = new EnumDescriptionAttribute("ResourceTest");
     Assert.Equal("ResourceTest", test.DescriptionResourceName);
     Assert.Equal("ResourceTest", test.Description);
     EnumDescriptionAttribute.SetResourcesProvider(new TestResourcesProvider());
     Assert.Equal("ResourceTest", test.DescriptionResourceName);
     Assert.Equal("ResourceTestTesting", test.Description);
 }
示例#2
0
        /// <summary>
        /// Get desc of specific enum value of specific enum type
        /// </summary>
        /// <param name="enumType"></param>
        /// <param name="enumIntValue"></param>
        /// <returns></returns>
        public static string GetDescription(Type enumType, int enumIntValue)
        {
            System.Text.StringBuilder sb    = new System.Text.StringBuilder();
            Dictionary <int, string>  descs = EnumDescriptionAttribute.GetDescriptions(enumType);

            Dictionary <int, string> .Enumerator en = descs.GetEnumerator();
            while (en.MoveNext())
            {
                if ((enumIntValue & en.Current.Key) == en.Current.Key)
                {
                    if (sb.Length == 0)
                    {
                        sb.Append(en.Current.Value);
                    }
                    else
                    {
                        sb.Append(',');
                        sb.Append(en.Current.Value);
                    }
                }
            }

            return(sb.ToString());
        }
示例#3
0
 public static string GetDescription(this Enum enumValue)
 {
     return(EnumDescriptionAttribute.GetDescription(enumValue));
 }
示例#4
0
 /// <summary>
 /// 获取枚举类型的注释
 /// </summary>
 /// <param name="enumT">枚举值</param>
 /// <returns></returns>
 public static string GetTypeDescription(this Enum enumT)
 {
     return(EnumDescriptionAttribute.GetEnumTyoeDescription(enumT.GetType()));
 }
示例#5
0
 /// <summary>
 /// 获取枚举的汉字说明,需要在枚举添加 [EnumDescriptionAttribute]
 /// </summary>
 /// <param name="enumSoruces"></param>
 /// <returns></returns>
 public static string GetDisplayText(this Enum enumSoruces)
 {
     return(EnumDescriptionAttribute.GetEnumDescription(enumSoruces));
 }