Report error when variable or function is not found
This commit is contained in:
@@ -17,11 +17,12 @@ namespace VAR.ExpressionEvaluator
|
|||||||
public object Eval(IEvaluationContext evaluationContext)
|
public object Eval(IEvaluationContext evaluationContext)
|
||||||
{
|
{
|
||||||
object[] paramValues = _paramNodes.Select(p => p.Eval(evaluationContext)).ToArray();
|
object[] paramValues = _paramNodes.Select(p => p.Eval(evaluationContext)).ToArray();
|
||||||
|
|
||||||
Func<object[], object> func = evaluationContext.GetFunction(_name);
|
Func<object[], object> func = evaluationContext.GetFunction(_name);
|
||||||
|
if (func == null)
|
||||||
|
{
|
||||||
|
throw new Exception(string.Format("Function {0} not found", _name));
|
||||||
|
}
|
||||||
object result = func(paramValues);
|
object result = func(paramValues);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
namespace VAR.ExpressionEvaluator
|
using System;
|
||||||
|
|
||||||
|
namespace VAR.ExpressionEvaluator
|
||||||
{
|
{
|
||||||
public class ExpressionVariableNode : IExpressionNode
|
public class ExpressionVariableNode : IExpressionNode
|
||||||
{
|
{
|
||||||
@@ -11,7 +13,12 @@
|
|||||||
|
|
||||||
public object Eval(IEvaluationContext evaluationContext)
|
public object Eval(IEvaluationContext evaluationContext)
|
||||||
{
|
{
|
||||||
return evaluationContext.GetVariable(_name);
|
object value = evaluationContext.GetVariable(_name);
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
throw new Exception(string.Format("Variable {0} not found", _name));
|
||||||
|
}
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user