CAMERA V1
This commit is contained in:
24
FATrace.HKNetLib/Common/EnumExtension.cs
Normal file
24
FATrace.HKNetLib/Common/EnumExtension.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace FATrace.HKNetLib.Common
|
||||
{
|
||||
public static class EnumExtension
|
||||
{
|
||||
public static string GetDesc<T>(this T em) where T : Enum
|
||||
{
|
||||
Type type = em.GetType();
|
||||
FieldInfo fd = type.GetField(em.ToString());
|
||||
|
||||
var num = Convert.ToInt32(em);
|
||||
if (fd == null)
|
||||
{
|
||||
return $"{num}";
|
||||
}
|
||||
var firstAttr = fd.GetCustomAttributes(typeof(DescriptionAttribute), false).FirstOrDefault();
|
||||
if (firstAttr == null) return $"{num}";
|
||||
|
||||
return (firstAttr as DescriptionAttribute).Description;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user