detect/detect.gui/Commons/Enums.cs
2024-11-13 17:09:15 +08:00

30 lines
723 B
C#

using System;
using System.ComponentModel;
namespace detect.gui.Commons;
public enum AlarmTypeEnum
{
[Description("报警1")]
type1,
[Description("报警2")]
type2,
[Description("报警3")]
type3,
[Description("报警4")]
type4,
[Description("报警5")]
type5
}
public static class EnumExtensions
{
public static string? GetDescription(this Enum val)
{
var field = val.GetType().GetField(val.ToString());
if (field == null) return null;
var customAttribute = Attribute.GetCustomAttribute(field, typeof(DescriptionAttribute));
return customAttribute == null ? val.ToString() : ((DescriptionAttribute)customAttribute).Description;
}
}