微信登录

配置 - Common公共码code DictTool字典工具

新建字典文件夹Tools

解决方案资源管理器—解决方案“Common”—右键—添加—新建项—文件夹
命名为:

  1. Tools

新建字典文件DictTool

解决方案资源管理器—解决方案“Common”—Common—右键—添加—新建项—类库
命名为:

  1. DictTool.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Common.Tools
  5. {
  6. public class DictTool
  7. {
  8. public static T2 GetValue<T1, T2>(Dictionary<T1,T2> dict, T1 key)
  9. {
  10. T2 value;
  11. bool isSuccess = dict.TryGetValue(key, out value);
  12. if (isSuccess)
  13. {
  14. return value;
  15. }
  16. else
  17. {
  18. return default(T2);
  19. }
  20. }
  21. }
  22. }
配置 - Common公共码code DictTool字典工具