首次上传
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
|
||||
namespace Sicentury.Core.Extensions
|
||||
{
|
||||
public static class EnumExtensionMethods
|
||||
{
|
||||
public static string GetDescription(this Enum genericEnum)
|
||||
{
|
||||
var genericEnumType = genericEnum.GetType();
|
||||
var memberInfo = genericEnumType.GetMember(genericEnum.ToString());
|
||||
if ((memberInfo.Length <= 0))
|
||||
return genericEnum.ToString();
|
||||
|
||||
var attributes = memberInfo[0]
|
||||
.GetCustomAttributes(typeof(System.ComponentModel.DescriptionAttribute), false);
|
||||
if ((attributes.Any()))
|
||||
{
|
||||
return ((System.ComponentModel.DescriptionAttribute)attributes.ElementAt(0)).Description;
|
||||
}
|
||||
|
||||
return genericEnum.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user