public static MethodInfo GetCalcMethod(TokenKind opKind, Type ltype, Type rtype) { CalculaterMethodTypeEnum calculaterMethodType = GetCalculaterMethodType(opKind, ltype, rtype); if (calculaterMethodType == CalculaterMethodTypeEnum.None) { return(null); } return(GetCalcMethod(calculaterMethodType, opKind, ltype, rtype)); }
private static MethodInfo GetCalcMethod(CalculaterMethodTypeEnum calculaterMethodType, TokenKind opKind, Type ltype, Type rtype) { Type calcType = typeof(Calculater); if (calculaterMethodType == CalculaterMethodTypeEnum.ContactString) { return(calcType.GetMethod("AddString")); } string opName = GetOpName(opKind); if (opName == null) { return(null); } string typeName = GetTypeName(ltype, rtype); if (typeName == null) { return(null); } string methodName = opName + typeName; if (calculaterMethodType == CalculaterMethodTypeEnum.MathOp) { return(calcType.GetMethod(methodName)); } if (calculaterMethodType == CalculaterMethodTypeEnum.MathDiv) { return(calcType.GetMethod(methodName)); } if (calculaterMethodType == CalculaterMethodTypeEnum.MathCompare) { return(calcType.GetMethod(methodName)); } if (calculaterMethodType == CalculaterMethodTypeEnum.RefCompare) { return(calcType.GetMethod(methodName)); } if (calculaterMethodType == CalculaterMethodTypeEnum.Logic) { return(calcType.GetMethod(methodName)); } return(null); }
public static Type GetRetType(CalculaterMethodTypeEnum calculaterMethodType, Type ltype, Type rtype) { if (calculaterMethodType == CalculaterMethodTypeEnum.None) { return(null); } if (calculaterMethodType == CalculaterMethodTypeEnum.ContactString) { return(typeof(string)); } if (calculaterMethodType == CalculaterMethodTypeEnum.MathOp) { if (ltype == typeof(int) || rtype == typeof(int)) { return(typeof(int)); } else { return(typeof(float)); } } if (calculaterMethodType == CalculaterMethodTypeEnum.MathDiv) { return(typeof(float)); } if (calculaterMethodType == CalculaterMethodTypeEnum.MathCompare) { return(typeof(bool)); } if (calculaterMethodType == CalculaterMethodTypeEnum.RefCompare) { return(typeof(bool)); } if (calculaterMethodType == CalculaterMethodTypeEnum.Logic) { return(typeof(bool)); } return(null); }