您的位置:首页 > 编程语言 > C#

C#基础-技术还债2-枚举

2016-10-28 17:08 190 查看
定一个枚举如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

namespace YX.Model
{
public class ValueAttribute : Attribute
{
public ValueAttribute(string value)
{
Value = value;
}
public string Value { get; private set; }

public static string GetCustomerValue(object code)
{
var ty = code.GetType();
var name = Enum.GetName(ty, code);
FieldInfo field = ty.GetField(name);
ValueAttribute attr = Attribute.GetCustomAttribute(field, typeof(ValueAttribute)) as ValueAttribute;
return attr.Value;
}
}
}


View Code
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: