using OpenTap;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Reflection;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace OpenTapEditor.Entity
|
{
|
public class EnumData
|
{
|
public string Name { get; set; }
|
public object Value { get; set; }
|
|
public static List<EnumData> GetFromEnum(Array arr)
|
{
|
List<EnumData> list = new List<EnumData>(arr.Length);
|
foreach (var item in arr)
|
{
|
if (item == null) continue;
|
string name = item.ToString();
|
// 获取枚举成员对应的字段信息
|
FieldInfo field = item.GetType().GetField(item.ToString());
|
if (field != null)
|
{
|
// 获取 DisplayAttribute
|
DisplayAttribute displayAttr = field.GetCustomAttribute<DisplayAttribute>();
|
if (displayAttr != null)
|
{
|
name = displayAttr.Name;
|
}
|
}
|
list.Add(new EnumData { Name = name, Value = item });
|
}
|
return list;
|
}
|
}
|
|
|
}
|