34 lines
938 B
C#
34 lines
938 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace JSMachine.WMS.Infrastructure
|
|
{
|
|
public static class EnumExtension
|
|
{
|
|
/// <summary>
|
|
/// 获取枚举描述属性值
|
|
/// </summary>
|
|
/// <param name="enum"></param>
|
|
/// <returns></returns>
|
|
public static string GetDescription(this Enum @enum)
|
|
{
|
|
Type type = @enum.GetType();
|
|
string name = Enum.GetName(type, @enum);
|
|
if (string.IsNullOrWhiteSpace(name))
|
|
return @enum.ToString();
|
|
|
|
FieldInfo field = type.GetField(name);
|
|
DescriptionAttribute des = field?.GetCustomAttribute<DescriptionAttribute>();
|
|
if (des == null)
|
|
return @enum.ToString();
|
|
|
|
return des.Description;
|
|
}
|
|
}
|
|
}
|