zoukankan      html  css  js  c++  java
  • 定义一个返回结果类型的类[原创] [小例子]

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

     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
  • 相关阅读:
    OAuth 2 深入介绍
    浅谈 EF CORE 迁移和实例化的几种方式
    为什么我们不应该使用微信或者 QQ 作为团队协作的 IM 工具?
    三值 bool? 进行与或运算后的结果
    Slack 开发入门之 Incoming Webhooks:往 Slack 的 Channel 中发消息
    int? 竟然真的可以是 null!.NET/C# 确定可空值类型 Nullable 实例的真实类型
    .NET 中使用 Mutex 进行跨越进程边界的同步
    UWP 在 WebView 中执行 JavaScript 代码(用于模拟用户输入等)
    谨慎使用 FileInfo.Exists 实例方法,而是使用 File.Exists 静态方法替代
    只需 5 秒钟,你就能取到 WPF 程序的超高分辨率超高清截图
  • 原文地址:https://www.cnblogs.com/winnxm/p/958403.html
Copyright © 2011-2022 走看看