mirror of
http://git.xinwangdao.com/cnnc-embedded-parts-detect/detect.git
synced 2025-06-24 21:44:12 +08:00
30 lines
723 B
C#
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;
|
|
}
|
|
}
|