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 :
///
break;
case :
///
break;
case :
///
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);
05-19 11:46