一:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
1.foreach
(int
val in
Enum.GetValues(typeof(AppEnum.HarbourStatus))){ ddlStatus.Items.Add(new
ListItem(Enum.GetName(typeof(AppEnum.HarbourStatus), val), val.ToString()));}ddlStatus.Items.FindByText(AppEnum.HarbourStatus.Avtal.ToString()).Selected = true;2.public
enum HarbourStatus{ Ans?kan = 1, Avtal = 2, Makulerad = 3, K?plats = 4} |
二:
var errorMes = respCode < 0 ? ((ProcessorStatus)respCode).ToDisplayString() : ((RedemptionStatus)respCode).ToDisplayString();
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128 |
using
System;using
System.Reflection;using
System.Resources;namespace
BallyACSCProvider.Util{ internal
enum ProcessorStatus : int { [DisplayString("Certificate Error")] CertError = -001, //certificate error [DisplayString("Retry Time out")] RetryOut = -002, //exceed retry time [DisplayString("Response Error")] ResponseError = -003, //error when get response NoResponse = -004, // no response need to be checked NoResponseCode=-005, //Has response, but no response code in response ResponseOk=0, // } internal
enum StartUpStatus : int { [DisplayString("Success")] Success = 000, [DisplayString("Invalid Version")] InvalidVersion = 001, [DisplayString("Invalid Release")] InvalidRelease = 002, [DisplayString("Invalid Corporate ID")] InvalidCorpID = 003, [DisplayString("Invalid Poroperty ID")] InvalidPropID = 004, [DisplayString("Unknown Kiosk")] UnknownKiosk = 005, } internal
enum ValidationStatus : int { [DisplayString("Accepted")] Accepted = 001, [DisplayString("Validate declined")] Declined = 002, } internal
enum RedemptionStatus : int { [DisplayString("Accepted")] Accepted = 001, [DisplayString("Redemption declined")] Declined = 002, } internal
enum ProviderStatus : int { Startup = 1, Terminated = 2, } /// <summary> /// Apply to properties or enum that are used in display description string. /// </summary> [AttributeUsage(AttributeTargets.All, Inherited = false, AllowMultiple = false)] internal
class DisplayStringAttribute : Attribute { internal
DisplayStringAttribute() { } internal
DisplayStringAttribute(string
value) { _value = value; } private
readonly string _value; internal
string Value { get { return
_value; } } internal
string ResourceKey { get; set; } } internal
static class EnumExtensions { internal
static string ToDisplayString(this
System.Enum en) { Type type = en.GetType(); MemberInfo[] memInfo = type.GetMember(en.ToString()); if
(memInfo.Length > 0) { object[] attrs = memInfo[0].GetCustomAttributes(typeof(DisplayStringAttribute), false); if
(attrs.Length > 0) { var
attr = ((DisplayStringAttribute)attrs[0]); return
!string.IsNullOrEmpty(attr.ResourceKey) ? GetStringByResourceKey(type, attr.ResourceKey) : attr.Value; } } return
en.ToString(); } private
static string GetStringByResourceKey(Type enumType, string
key) { if
(string.IsNullOrEmpty(key)) return
string.Empty; var
rm = new
ResourceManager(enumType); return
rm.GetString(key); } }} |
原文:http://www.cnblogs.com/cw_volcano/p/3566340.html