12345678910111213141516171819202122232425262728293031323334353637 |
-
- using System.ComponentModel;
- using System.Reflection;
- namespace JBIM.Common
- {
- public static class EnumExtensions
- {
-
-
-
-
-
- public static string GetDescription<T>(this T t) where T : struct
- {
- string description = t.ToString();
- FieldInfo fieldInfo = t.GetType().GetField(description);
- object[] attributes = fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
- if (attributes.Length > 0)
- {
- DescriptionAttribute info = attributes[0] as DescriptionAttribute;
- if (info != null)
- {
- description = info.Description;
- }
- }
- return description;
- }
- }
- }
|