个人随笔-剔除某个枚举选项

 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.未选择); 
原文地址:https://www.cnblogs.com/lijianhong90/p/15204642.html