foreach on enum with Custom Attributes
This question already has an answer here:
你的意思是这样吗?
class Program
{
static void Main()
{
foreach (var field in typeof(TableName).GetFields(BindingFlags.Static | BindingFlags.Public))
{
ProcessField(field);
}
}
static void ProcessField(FieldInfo field)
{
ProcessD(field.GetCustomAttribute(typeof(DescriptionAttribute)) as DescriptionAttribute);
ProcessDWV(field.GetCustomAttribute(typeof(DescriptionWithValueAttribute)) as DescriptionWithValueAttribute);
}
static void ProcessD(DescriptionAttribute attribute)
{
if(attribute != null)
{
//...
}
}
static void ProcessDWV(DescriptionWithValueAttribute attribute)
{
if (attribute != null)
{
//...
}
}
链接地址: http://www.djcxy.com/p/91498.html
上一篇: 如何将枚举转换为C#中的列表?
下一篇: 使用自定义属性对枚举进行foreach