You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using ICSSoft.Frame.Data.Entity;
|
|
|
|
namespace ICSSoft.Frame.Common
|
|
{
|
|
public static class EnumExtfunction
|
|
{
|
|
public static string GetDescription<Attr>(this Enum em) where Attr : AttrDescription
|
|
{
|
|
Type enumType = em.GetType();
|
|
var name = Enum.GetName(enumType, em);
|
|
if (name == null)
|
|
return string.Empty;
|
|
object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(Attr), false);
|
|
if (objs == null || objs.Length == 0)
|
|
return string.Empty;
|
|
Attr attr = objs[0] as Attr;
|
|
return attr.Description;
|
|
}
|
|
|
|
public static string GetDescription(this Enum em)
|
|
{
|
|
Type enumType = em.GetType();
|
|
var name = Enum.GetName(enumType, em);
|
|
if (name == null)
|
|
return string.Empty;
|
|
object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
|
|
if (objs == null || objs.Length == 0)
|
|
return string.Empty;
|
|
System.ComponentModel.DescriptionAttribute attr = objs[0] as System.ComponentModel.DescriptionAttribute;
|
|
return attr.Description;
|
|
}
|
|
}
|
|
}
|