首页 > 代码库 > Enum使用
Enum使用
public enum DiscountType
{
[Description("001")]
ComboDiscount,
[Description("002")]
AutoDiscount,
[Description("003")]
ShippingPromotion,
[Description("004")]
Com,
[Description("005")]
PromotionCode,
[Description("006")]
RushOrder,
[Description("008")]
EggPoint,
[Description("009")]
PremierDiscount,
[Description("010")]
RushOrderFee
}
//获取枚举的Description信息
public static string GetEnumDescription(Enum e)
{
FieldInfo enumInfo = e.GetType().GetField(e.ToString());
DescriptionAttribute[] enumAttributes = (DescriptionAttribute[])enumInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
if (enumAttributes.Length > 0)
{
return enumAttributes[0].Description;
}
return e.ToString();
}