EvaluationContext: Assure only the 3 types (decimal, string and bool)
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user