You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
943 B
C#
35 lines
943 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Myshipping.Core.Helper
|
|
{
|
|
public static class EnumHelper
|
|
{
|
|
/// <summary>
|
|
/// 获取枚举值的description文本
|
|
/// </summary>
|
|
/// <param name="type"></param>
|
|
/// <param name="strVal"></param>
|
|
/// <returns></returns>
|
|
public static string GetDescription(Type type, string strVal)
|
|
{
|
|
System.Reflection.FieldInfo field = type.GetField(strVal);
|
|
if (field != null)
|
|
{
|
|
var attribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute)) as DescriptionAttribute;
|
|
if (attribute != null)
|
|
{
|
|
return attribute.Description;
|
|
}
|
|
}
|
|
|
|
return string.Empty;
|
|
}
|
|
|
|
}
|
|
}
|