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.

20 lines
536 B

1 month ago
using System;
using System.ComponentModel;
using System.Reflection;
namespace ServerComm
{
public static class EnumHelper
{
// 获取枚举的字符串描述
public static string GetEnumDescription(Enum value)
{
var field = value.GetType().GetField(value.ToString());
if (field == null) return "";
var attribute = field.GetCustomAttribute<DescriptionAttribute>();
return attribute == null ? value.ToString() : attribute.Description;
}
}
}