using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
Status a = (Status)2;
Console.WriteLine(a.ToString());
Console.WriteLine(a.ToDescription());
Console.ReadKey();
}
public enum Status
{
[Description("零")]
Zero = 0,
[Description("一")]
One = 1,
[Description("二")]
Two = 2
}
}
public static class StringExtensions
{
public static string ToDescription(this Enum value)
{
if (value == null)
return "";
System.Reflection.FieldInfo fieldInfo = value.GetType().GetField(value.ToString());
object[] attribArray = fieldInfo.GetCustomAttributes(false);
if (attribArray.Length == 0)
return value.ToString();
else
return (attribArray[0] as DescriptionAttribute).Description;
}
}
}