public static Boolean EvaluateValueOrMethod( Object Obj, String FieldOrMethodName, Int32 ParametersCount, DynContext DynLanContext) { Boolean seekInObject = (Obj != null && !(Obj is EmptyObject)); Boolean wasValueFoundFromContext = false; Boolean wasValueFoundInObject = false; Boolean wasValueFoundInExpressions = false; ExpressionValue expressionValue = DynLanContext.GetValue( DynLanContext, FieldOrMethodName, seekInObject, !seekInObject, !seekInObject); if (expressionValue != null) { wasValueFoundFromContext = true; } if (seekInObject) { Boolean foundValue = false; Object value = GetValueFromObject( Obj, FieldOrMethodName, ParametersCount, expressionValue != null, out foundValue); if (foundValue) { wasValueFoundInObject = true; if (value is MethodInfo) { OnpMethodInfo methodInfo = new OnpMethodInfo(); methodInfo.Obj = Obj; methodInfo.MethodName = FieldOrMethodName; DynLanContext.CurrentExpressionState.PushValue(methodInfo); return(false); } else { DynLanContext.CurrentExpressionState.PushValue(value); return(false); } } } Expression expression = DynLanContext. CurrentExpressionGroup. FindExpression(FieldOrMethodName, DynLanContext); if (expression == null) { Object value = expressionValue == null ? null : expressionValue.Value; value = InternalTypeConverter.ToInner( value); #if !IGNORE_NOT_DECLARED_VARIABLES if (!wasValueFoundFromContext && !wasValueFoundInObject) { if (seekInObject) { throw new DynLanVariableNotFoundException("Variable " + FieldOrMethodName + " not found in object " + Obj + "!") { Variable = FieldOrMethodName } } ; throw new DynLanVariableNotFoundException("Variable " + FieldOrMethodName + " not found!") { Variable = FieldOrMethodName }; } #endif DynLanContext.CurrentExpressionState.PushValue(value); return(false); } else { wasValueFoundInExpressions = true; ExpressionState newExpressionState = new ExpressionState(); newExpressionState.Expression = expression; DynLanContext.CurrentExpressionContext.Stack.Add(newExpressionState); return(false); } } }
private static ExpressionMethodResult EvaluateInlineMethod( Object Object, Object Method, IList <Object> MethodParameters, DynLanContext DynLanContext) { if (Method is OnpMethodInfo) { OnpMethodInfo methodInfo = Method as OnpMethodInfo; DynamicCallResult callResult = MyReflectionHelper.CallMethod( methodInfo.Obj, methodInfo.MethodName, CorrectParameters(MethodParameters)); if (callResult != null) { return(new ExpressionMethodResult(callResult.Value)); } } else if (Method is OnpActionMethodInfo) { OnpActionMethodInfo methodInfo = Method as OnpActionMethodInfo; if (methodInfo != null && methodInfo.Action != null) { return(new ExpressionMethodResult(methodInfo.Action(CorrectParameters(MethodParameters)))); } } else if (Method is ExpressionMethod) { ExpressionMethod onpMethod = Method as ExpressionMethod; ExpressionMethodResult result = null; if (Object is EmptyObject) { result = onpMethod. CalculateValueDelegate( DynLanContext, CorrectParameters(MethodParameters)); } else { #if !NET20 var tmp = new[] { Object }.Union(MethodParameters); #else var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray(); #endif result = onpMethod. CalculateValueDelegate( DynLanContext, CorrectParameters(tmp)); } 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( DynLanContext, CorrectParameters(MethodParameters)); } else { #if !NET20 var tmp = new[] { Object }.Union(MethodParameters); #else var tmp = Linq2.From(new[] { Object }).Union(MethodParameters).ToArray(); #endif result = onpMethod. CalculateValueDelegate( DynLanContext, CorrectParameters(tmp)); } if (result != null) { result.Value = InternalTypeConverter.ToInner(result.Value); } return(result == null ? new ExpressionMethodResult(null) : result); } else if (Method is ExpressionExtender) { ExpressionExtender onpExtender = Method as ExpressionExtender; return(new ExpressionMethodResult( onpExtender. CalculateValueDelegate( DynLanContext, 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( DynLanContext, Object, MethodParameters))); } else if (Method is Delegate) { #if NETCE throw new NotSupportedException("Calling delegates is forbidden on wince2.0!"); #else Delegate m = Method as Delegate; DynamicCallResult callResult = MyReflectionHelper.CallMethod( m.Target, m.Method, CorrectParameters(MethodParameters)); if (callResult != null) { return(new ExpressionMethodResult(callResult.Value)); } #endif } if (Method == null) { if (Object == null) { throw new DynLanMethodNotFoundException("Cannot find a method to call"); } else { throw new DynLanMethodNotFoundException("Cannot find a method to call in object " + Object.GetType().Name + ""); } } throw new DynLanUnsupportedMethodTypeException("Unsupported method type " + Method.GetType() + "!"); }