/// <summary> /// Evaluates function represented by this node. /// </summary> /// <param name="context">Context to evaluate expressions against.</param> /// <param name="evalContext">Current expression evaluation context.</param> /// <returns>Result of the function evaluation.</returns> protected override object Get(object context, EvaluationContext evalContext) { string name = this.getText(); IDictionary locals = evalContext.LocalVariables; LambdaExpressionNode lambda = locals[name] as LambdaExpressionNode; if (lambda == null) { throw new InvalidOperationException("Function '" + name + "' is not defined."); } object[] argValues = ResolveArguments(evalContext); try { return(GetValueWithArguments(lambda, context, evalContext, argValues)); } catch (ArgumentMismatchException ame) { throw new InvalidOperationException("Failed executing function '" + name + "': " + ame.Message); } }
/// <summary> /// Evaluates function represented by this node. /// </summary> /// <param name="context">Context to evaluate expressions against.</param> /// <param name="evalContext">Current expression evaluation context.</param> /// <returns>Result of the function evaluation.</returns> protected override object Get(object context, EvaluationContext evalContext) { string name = this.getText(); object[] argValues = ResolveArguments(evalContext); object function = evalContext.Variables[name]; // delegate? Delegate callback = function as Delegate; if (callback != null) { return(InvokeDelegate(callback, argValues)); } // lambda? LambdaExpressionNode lambda = function as LambdaExpressionNode; if (lambda != null) { try { return(GetValueWithArguments(lambda, context, evalContext, argValues)); } catch (ArgumentMismatchException ame) { throw new InvalidOperationException("Failed executing function " + name + ": " + ame.Message); } } if (function == null) { throw new InvalidOperationException("Function '" + name + "' is not defined."); } throw new InvalidOperationException("Function '" + name + "' is defined but of unknown type."); }