public static ActionResult ToEnumJsonResult(Type type, int exportValue=-1) { var EnumWrappers = new List<EnumWrapper>(); foreach (var t in Enum.GetNames(type)) { var field = type.GetField(t); if (field != null) { if (field.GetCustomAttribute<ReflectionDisabledAttribute>() != null) continue; } if (Convert.ToInt32(Enum.Parse(type, t)) != exportValue) { EnumWrappers.Add(new EnumWrapper { ID = Convert.ToInt32(Enum.Parse(type, t)), Name = t }); } } return JsonHelper.Create(EnumWrappers); }
调用:
var result = ToEnumJsonResult(typeof(EKindType), (int)EKindType.未选择);