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 GetFromEnum(Array arr) { List list = new List(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(); if (displayAttr != null) { name = displayAttr.Name; } } list.Add(new EnumData { Name = name, Value = item }); } return list; } } }