public static dynamic Break <T>(this SwitchSugarModel <T> switchSugar) { string reval = switchSugar.ReturnVal; switchSugar = null;//清空对象,节约性能 return(reval); }
/// <summary> /// Switch().Case().Default().Break() /// </summary> /// <typeparam name="T"></typeparam> /// <param name="thisValue"></param> /// <returns></returns> public static SwitchSugarModel <T> Switch <T>(this T thisValue) { var reval = new SwitchSugarModel <T>(); reval.SourceValue = thisValue; return(reval); }
public static SwitchSugarModel <T> Default <T, TReturn>(this SwitchSugarModel <T> switchSugar, TReturn returnValue) { if (switchSugar.IsEquals == false) { switchSugar.ReturnVal = returnValue; } return(switchSugar); }
public static SwitchSugarModel <T> Case <T, TReturn>(this SwitchSugarModel <T> switchSugar, T caseValue, TReturn returnValue) { if (switchSugar.SourceValue.Equals(caseValue)) { switchSugar.IsEquals = true; switchSugar.ReturnVal = returnValue; } return(switchSugar); }