public static Boolean EvaluateValueOrMethod( Object Obj, String FieldOrMethodName, Int32 ParametersCount, PainContext PainContext) { Boolean seekInObject = (Obj != null && !(Obj is EmptyObject)); if (seekInObject) { Boolean foundValue = false; Object value = GetValueFromObject( Obj, FieldOrMethodName, ParametersCount, out foundValue); if (foundValue) { if (value is MethodInfo) { OnpMethodInfo methodInfo = new OnpMethodInfo(); methodInfo.Obj = Obj; methodInfo.Name = FieldOrMethodName; PainContext.CurrentExpressionState.PushValue(methodInfo); return(false); } else { PainContext.CurrentExpressionState.PushValue(value); return(false); } } } ExpressionValue expressionValue = null; Expression expression = null; expression = PainContext. CurrentExpressionGroup. FindExpression(FieldOrMethodName, PainContext); if (expression == null) { expressionValue = PainContext.GetValue( PainContext, FieldOrMethodName, seekInObject, !seekInObject, !seekInObject); } if (expression == null) { Object value = expressionValue == null ? null : expressionValue.Value; value = InternalTypeConverter.ToInner( value); PainContext.CurrentExpressionState.PushValue(value); return(false); } else { ExpressionState newExpressionState = new ExpressionState(); newExpressionState.Expression = expression; PainContext.CurrentExpressionContext.Stack.Add(newExpressionState); return(false); } }
private static ExpressionMethodResult EvaluateInlineMethod( Object Object, Object Method, IList <Object> MethodParameters, PainContext PainContext) { if (Method is OnpMethodInfo) { OnpMethodInfo methodInfo = Method as OnpMethodInfo; DynamicCallResult callResult = MyReflectionHelper.CallMethod( methodInfo.Obj, methodInfo.Name, MethodParameters); if (callResult != null) { return(new ExpressionMethodResult(callResult.Value)); } } else if (Method is ExpressionMethod) { ExpressionMethod onpMethod = Method as ExpressionMethod; ExpressionMethodResult result = null; if (Object is EmptyObject) { result = onpMethod. CalculateValueDelegate( PainContext, MethodParameters); } else { result = onpMethod. CalculateValueDelegate( PainContext, new[] { Object }.Union(MethodParameters).ToArray()); } return(result == null ? new ExpressionMethodResult(null) : result); } else if (Method is ExpressionMethodInfo) { ExpressionMethodInfo onpMethodInfo = Method as ExpressionMethodInfo; ExpressionMethod onpMethod = BuildinMethods.GetByID(onpMethodInfo.ID); ExpressionMethodResult result = null; if (onpMethod == null) { return(new ExpressionMethodResult(result)); } if (Object is EmptyObject) { result = onpMethod. CalculateValueDelegate( PainContext, MethodParameters); } else { result = onpMethod. CalculateValueDelegate( PainContext, new[] { Object }.Union(MethodParameters).ToArray()); } return(result == null ? new ExpressionMethodResult(null) : result); } else if (Method is ExpressionExtender) { ExpressionExtender onpExtender = Method as ExpressionExtender; return(new ExpressionMethodResult( onpExtender. CalculateValueDelegate( PainContext, Object, MethodParameters))); } else if (Method is ExpressionExtenderInfo) { ExpressionExtenderInfo onpExtenderInfo = Method as ExpressionExtenderInfo; ExpressionExtender onpExtender = BuildinExtenders.GetByID(onpExtenderInfo.ID); if (onpExtender == null) { return(new ExpressionMethodResult(null)); } return(new ExpressionMethodResult( onpExtender. CalculateValueDelegate( PainContext, Object, MethodParameters))); } if (Method == null) { if (Object == null) { throw new PainMethodNotFoundException("Cannot find a method to call"); } else { throw new PainMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + ""); } } throw new PainUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!"); }