EvaluationContext: Assure only the 3 types (decimal, string and bool)

This commit is contained in:
2019-12-02 02:08:27 +01:00
parent 4e5f0bdfab
commit 071a6d8d43

View File

@@ -15,11 +15,20 @@ namespace VAR.ExpressionEvaluator
public void SetFunction(string name, Func<object[], object> function)
{
if (_functions.ContainsKey(name))
{
_functions[name] = function;
return;
}
_functions.Add(name, function);
}
public Func<object[], object> GetFunction(string name)
{
if (_functions.ContainsKey(name) == false)
{
return null;
}
return _functions[name];
}
@@ -30,11 +39,29 @@ namespace VAR.ExpressionEvaluator
public void SetVariable(string name, object value)
{
if (value is DateTime)
{
value = ((DateTime)value).ToString("s");
}
if ((value is string) == false && (value is bool) == false)
{
value = Convert.ToDecimal(value);
}
if (_variables.ContainsKey(name))
{
_variables[name] = value;
return;
}
_variables.Add(name, value);
}
public object GetVariable(string name)
{
if (_variables.ContainsKey(name) == false)
{
return null;
}
return _variables[name];
}