定义一个返回结果类型的类[原创] [小例子]

本文介绍了一个用于定义ACC认证返回结果的数据字典实现。通过这个字典,可以将特定的返回码映射到相应的中文解释,便于理解各种认证过程中可能遇到的不同情况。

工作中,因为有好多的返回结果,而且都有着不同的结果和意义,于是就用了数据字典来定义了部分。
详见代码。其中只列出了部分类型。

 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4
 5namespace 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
14        /**//// <summary>
15        /// 私有构造函数,以防止创建该类的实例
16        /// </summary>

17        private ACCValidateLastResult()
18        
19        }

20
21        /**//// <summary>
22        /// 类的构造函数,在类(而不是实例)首次使用时调用,且在类的生命周期中仅调用一次
23        /// </summary>

24        static ACCValidateLastResult()
25        {
26            if (!InitACCValidateLastResult())
27                throw new Exception();
28        }

29
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
58            return true;
59        }

60
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

转载于:https://www.cnblogs.com/winnxm/archive/2007/11/13/958403.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值