//1.MyEnum:
textBox2.Text = "MyEnumTest:";
//>>>1.获得枚举类型的文字描述:
textBox2.Text += Environment.NewLine + EnumDescription.GetEnumText(typeof(MyEnum));
//>>>2.获得某个枚举值的文字描述:
textBox2.Text += Environment.NewLine + EnumDescription.GetFieldText(MyEnum.I);
//>>>3.获得枚举中各个字段的定义数组:
var filedTexts = EnumDescription.GetFieldTexts(typeof(MyEnum));//3.
string result = string.Empty;
foreach (EnumDescription val in filedTexts) {
result += Environment.NewLine + string.Format("MyEnum的成员:{0} 数字值:{1} 描述文本:{2}", val.FieldName, val.EnumValue, val.EnumDisplayText); }
textBox2.Text += result;
//>>>4.绑定到下拉框:
comboBox2.DisplayMember = "EnumDisplayText";
comboBox2.ValueMember = "EnumValue";
//comboBox2.DataSource = EnumDescription.GetFieldTexts(
// typeof(MyEnum),
// EnumDescription.SortType.Rank);
comboBox2.DataSource = EnumDescription.GetFieldTexts(typeof(MyEnum),EnumDescription.SortType.DisplayText);
[EnumDescription("人称")]
enum MyEnum {
[EnumDescription("你", 1)]
You = 1,
[EnumDescription("我", 2)]
I = 2,
[EnumDescription("他", 3)]
He = 4,
[EnumDescription("她", 4)]
She = 8
}
[EnumDescription("工作进度")]
enum WorkState {
[EnumDescription("计划制定中")] Planing,
[EnumDescription("一切就绪")] Ready,
[EnumDescription("工作进行中")] Processing,
[EnumDescription("完成工作")] Finished }