定义一个返回结果类型的类[原创] [小例子]
工作中,因为有好多的返回结果,而且都有着不同的结果和意义,于是就用了数据字典来定义了部分。
详见代码。其中只列出了部分类型。
1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4![](/Images/OutliningIndicators/None.gif)
5
namespace AFC.BOM.Constants.Prompt
6
{
7
/// <summary>
8
/// ACC 认证返回结果 后四位 (LLLL代码)类型定义
9
/// </summary>
10
public class ACCValidateLastResult
11
{
12
private static Dictionary<int,string> accValidateLastResult = new Dictionary<int,string>();
13![](/Images/OutliningIndicators/InBlock.gif)
14
/// <summary>
15
/// 私有构造函数,以防止创建该类的实例
16
/// </summary>
17
private ACCValidateLastResult()
18
{
19
}
20![](/Images/OutliningIndicators/InBlock.gif)
21
/// <summary>
22
/// 类的构造函数,在类(而不是实例)首次使用时调用,且在类的生命周期中仅调用一次
23
/// </summary>
24
static ACCValidateLastResult()
25
{
26
if (!InitACCValidateLastResult())
27
throw new Exception();
28
}
29![](/Images/OutliningIndicators/InBlock.gif)
30
/// <summary>
31
/// 初始化各种操作结果对应的中文信息
32
/// </summary>
33
/// <returns></returns>
34
private static bool InitACCValidateLastResult()
35
{
36
try
37
{
38
/*
39
* LLLL代码含义 LLLL 说明
40
* */
41
accValidateLastResult.Add(0, "认证成功!");
42
accValidateLastResult.Add(5, "等待超时!");
43
accValidateLastResult.Add(0x6283,"选择文件无效,文件或密钥校验错误,可能不是一票通sam卡!");
44
accValidateLastResult.Add(0x6581,"写EEPROM不成功 ");
45
accValidateLastResult.Add(0x6983,"密钥被锁死!");
46
accValidateLastResult.Add(0x9302,"MAC错误!");
47
accValidateLastResult.Add(0x9403,"密钥未找到!");
48
accValidateLastResult.Add(0x9406,"所需MAC不可用!");
49
accValidateLastResult.Add(0xFEFC,"网络收发超时!");
50
accValidateLastResult.Add(0xFEFB,"Sam卡已列入黑名单!");
51
accValidateLastResult.Add(0xFEFA,"Sam卡不存在!");
52
}
53
catch
54
{
55
return false;
56
}
57![](/Images/OutliningIndicators/InBlock.gif)
58
return true;
59
}
60![](/Images/OutliningIndicators/InBlock.gif)
61
/// <summary>
62
/// 通过索引来返回错误提示信息
63
/// </summary>
64
/// <param name="index">错误索引</param>
65
/// <returns></returns>
66
public static string GetaccValidateLastResultInfo(int index)
67
{
68
try
69
{
70
if (accValidateLastResult.ContainsKey(index))
71
return accValidateLastResult[index];
72
}
73
catch
74
{}
75
return "其他错误(" + index.ToString("X4") + ")!";
76
}
77
}
78
}
79![](/Images/OutliningIndicators/None.gif)
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/None.gif)
3
![](/Images/OutliningIndicators/None.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/None.gif)
6
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
7
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
17
![](/Images/OutliningIndicators/InBlock.gif)
18
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
19
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/InBlock.gif)
28
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
29
![](/Images/OutliningIndicators/InBlock.gif)
30
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
31
![](/Images/OutliningIndicators/InBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
38
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/InBlock.gif)
47
![](/Images/OutliningIndicators/InBlock.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
50
![](/Images/OutliningIndicators/InBlock.gif)
51
![](/Images/OutliningIndicators/InBlock.gif)
52
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
55
![](/Images/OutliningIndicators/InBlock.gif)
56
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
57
![](/Images/OutliningIndicators/InBlock.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
60
![](/Images/OutliningIndicators/InBlock.gif)
61
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
62
![](/Images/OutliningIndicators/InBlock.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/InBlock.gif)
65
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
66
![](/Images/OutliningIndicators/InBlock.gif)
67
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
68
![](/Images/OutliningIndicators/InBlock.gif)
69
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
70
![](/Images/OutliningIndicators/InBlock.gif)
71
![](/Images/OutliningIndicators/InBlock.gif)
72
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
73
![](/Images/OutliningIndicators/InBlock.gif)
74
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
75
![](/Images/OutliningIndicators/InBlock.gif)
76
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
77
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
78
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
79
![](/Images/OutliningIndicators/None.gif)