using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
namespace EnumAttributeTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(GetEnumDescirbeString<TestEnum>(TestEnum.SecondType));
}
public static string GetEnumDescirbeString<T>(T I_EnumValue)
{
return ((DescribeAttribute)typeof(T).GetField(I_EnumValue.ToString()).GetCustomAttributes(typeof(DescribeAttribute), false)[0]).Describe;
}
}
public enum TestEnum
{
[Describe("aaa")]
FirstType,
[Describe("bbb")]
SecondType,
[Describe("ccc")]
ThirdType,
}
public class DescribeAttribute : Attribute
{
private string m_describe;
public string Describe
{
get { return m_describe; }
set { m_describe = value; }
}
public DescribeAttribute(string describe)
{
m_describe = describe;
}
}
}