public override void Visit(Identifier function) { if (_context == null) { _result = L.Expression.Constant(_parameters[function.Name]); } else { var args = new ParameterArgs(); OnEvaluateParameter(function.Name, args); if (args.HasResult) { _result = L.Expression.Constant(args.Result); return; } _result = L.Expression.PropertyOrField(_context, function.Name); } }
/// <summary> /// Parameter evaluator called off by function EvaluateExpression so as to elimiate the need of trying to cast the expression parameters to a more defined type. /// Additionally it adds the possibility that an expression parameter itself can be of complex type. /// </summary> /// <param name="name">name of the parameter</param> /// <param name="args">ParameterArgs object where to store the evaluation result</param> private void EvaluateParam(string name, ParameterArgs args) { if (this._definesHandler.SubstitutionTokens.ContainsKey(name)) { object substituionText; this._definesHandler.SubstitutionTokens.TryGetValue(name, out substituionText); Expression parameterExpression = new Expression((string)substituionText); parameterExpression.EvaluateParameter += EvaluateParam; try { args.Result = parameterExpression.Evaluate(); } catch (EvaluationException) { //in case an exception occurred we do not set args and hence the evaluation will be undefined } } //in case the key is not found we do not set args and hence the evaluation will be undefined }
private void OnEvaluateParameter(string name, ParameterArgs args) => EvaluateParameter?.Invoke(name, args);