20220313 3张表格 导出excel功能
This commit is contained in:
32
20220313_Excel/TempTask.WebEntry/Tools/EnumHelper.cs
Normal file
32
20220313_Excel/TempTask.WebEntry/Tools/EnumHelper.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace TempTask.WebEntry.Tools
|
||||
{
|
||||
public class EnumHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 得到枚举的DescriptionAttribute值。
|
||||
/// </summary>
|
||||
/// <typeparam name="TEnum"></typeparam>
|
||||
/// <param name="value"></param>
|
||||
/// <returns></returns>
|
||||
static public string GetEnumDescription<TEnum>(object value)
|
||||
{
|
||||
Type enumType = typeof(TEnum);
|
||||
if (!enumType.IsEnum)
|
||||
throw new ArgumentException("不是枚举类型");
|
||||
var name = Enum.GetName(enumType, value);
|
||||
if (name == null)
|
||||
return string.Empty;
|
||||
object[] objs = enumType.GetField(name).GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
if (objs == null || objs.Length == 0)
|
||||
return string.Empty;
|
||||
DescriptionAttribute attr = objs[0] as DescriptionAttribute;
|
||||
return attr.Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user