public static CodegenExpression CodegenPluginDTM( DateTimeMethodMode mode, Type returnedClass, Type firstParameterClass, CodegenExpression firstParameterExpression, IList <ExprNode> paramExpressions, CodegenMethodScope parent, ExprForgeCodegenSymbol symbols, CodegenClassScope classScope) { var staticMethod = (DateTimeMethodModeStaticMethod)mode; var method = parent.MakeChild(returnedClass, typeof(DTMPluginValueChangeForge), classScope).AddParam(firstParameterClass, "dt"); var @params = new CodegenExpression[paramExpressions.Count + 1]; @params[0] = Ref("dt"); for (var i = 0; i < paramExpressions.Count; i++) { var forge = paramExpressions[i].Forge; @params[i + 1] = forge.EvaluateCodegen(forge.EvaluationType, method, symbols, classScope); } var callStatic = StaticMethod(staticMethod.Clazz, staticMethod.MethodName, @params); if (returnedClass == typeof(void)) { method.Block.Expression(callStatic); } else { method.Block.MethodReturn(callStatic); } return(LocalMethod(method, firstParameterExpression)); }
public static void ValidateDTMStaticMethodAllowNull( Type inputType, DateTimeMethodMode mode, Type firstParameter, IList <ExprNode> paramExpressions) { if (mode == null) { if (inputType == firstParameter) { throw new ExprValidationException("Plugin datetime method does not provide a forge for input type " + inputType.CleanName()); } return; } if (!(mode is DateTimeMethodModeStaticMethod)) { throw new ExprValidationException("Unexpected plug-in datetime method mode implementation " + mode.GetType()); } var staticMethod = (DateTimeMethodModeStaticMethod)mode; var @params = new Type[paramExpressions.Count + 1]; @params[0] = firstParameter; for (var i = 0; i < paramExpressions.Count; i++) { @params[i + 1] = paramExpressions[i].Forge.EvaluationType; } try { MethodResolver.ResolveMethod( staticMethod.Clazz, staticMethod.MethodName, @params, false, new bool[@params.Length], new bool[@params.Length]); } catch (MethodResolverNoSuchMethodException ex) { throw new ExprValidationException("Failed to find static method for date-time method extension: " + ex.Message, ex); } }