• ClassifyHandler 分类处理结构


     
    public class ClassifyHandler
            {
                public object vTrue { get; set; }
                public object vFalse { get; set; }
    
                public Action fnTrue { get; set; }
                public Action fnFalse { get; set; }
    
                public static object GetMatchResult(bool ss, ClassifyHandler t2)
                {
                    if (ss) return t2.vTrue;
                    return t2.vFalse;
                }
                public static void ExecuteMatchEvent(bool ss, ClassifyHandler t2)
                {
                    if (ss && t2.fnTrue != null) t2.fnTrue();
                    t2.fnFalse?.Invoke();
                }
                public static void ExecuteMatchEvents(object val,Dictionary<object,Action> objs)
                {
                    foreach (object item in objs)
                    {
                        if (item == val && objs[item] != null)
                        {
                            objs[item]();
                        }
                    }
                }
            }
    GetMatchResult 替换了以下内容:
    var res="";
    if(ss){
      res = t2.vTrue;
    }
    else{
      res = t2.vFalse;
    }
    ExecuteMatchEvent替换了以下内容:
    if(ss){
      t2.fnTrue(); //执行A功能
    }
    else{
       t2.fnFalse();//执行B功能
    }
    ExecuteMatchEvents替换了以下内容:
    switch(num)
    {
       case 1:
          ///
       break;  
       case 2:
          ///
       break;  
       case 3:
          ///
       break;  
    }
    调用方法
     var ch = new ClassifyHandler()
     {
         vTrue = "true",
         vFalse = "false"
     };
    
     var dic = new Dictionary<object, Action>();
     dic.Add(2, () =>
     {
         var res = ClassifyHandler.GetMatchResult(!isExport, ch);
     });
     dic.Add(3, () =>
     {
         //处理
     });
     
    ClassifyHandler.ExecuteMatchEvents(2
    , dic);
  • 相关阅读:
    作业11图
    作业11
    作业10
    总结一
    物联网相关知识
    第十二次作业
    附加题4
    第十一次作业
    附加题3
    第十次作业
  • 原文地址:https://www.cnblogs.com/licin/p/6565405.html
Copyright © 2020-2023  润新知