Files
MsAddIns/ExportExcelTest/Models/EnumExtensions.cs
2026-02-28 21:01:57 +08:00

18 lines
508 B
C#

using System;
using System.ComponentModel;
using System.Linq;
namespace CustomOpenAddins.Models
{
static class EnumExtensions
{
public static string GetDescription(this Enum val)
{
var field = val.GetType().GetField(val.ToString());
var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
}
}
}