Web/App_Code/EnumHelper.cs
(开头部分) 3KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
#region license
/*****************************************
*Function :
* at 2014/1/11 9:13:58.
*E-Mail: jijunjian@iWMPT.com
*****************************************/
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
using System.Web.UI.WebControls;
namespace WMPT.Common
{
/// <summary>
/// 枚举辅助类
/// </summary>
public static class EnumHelper
{
/// <summary>
/// 获得枚举类型数据项(不包括空项)
/// </summary>
/// <param name="enumType">枚举类型</param>
/// <returns></returns>
public static IList<ListItem> GetItems(this Type enumType)
{
if (!enumType.IsEnum)
throw new InvalidOperationException();
IList<ListItem> list = new List<ListItem>();
// 获取Description特性
Type typeDescription = typeof(DescriptionAttribute);
// 获取枚举字段
FieldInfo[] fields = enumType.GetFields();
foreach (FieldInfo field in fields)
{
if (!field.FieldType.IsEnum)
continue;
// 获取枚举值
int value = (int)enumType.InvokeMember(field.Name, BindingFlags.GetField, null, null, null);
// 不包括空项
if (value >= 0)
{
string text = string.Empty;
object[] array = field.GetCustomAttributes(typeDescription, false);
if (array.Length > 0) text = ((DescriptionAttribute)array[0]).Description;
else text = field.Name; //没有描述,直接取值
//添加到列表
list.Add(new ListItem(text, value.ToString()));
}
}
后面还有 46 行代码,购买后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明
AI 解读 AI
登录后可用,每次 10 算力,解读结果公开显示在下面。
还没有人解读过这个文件。
