|
@@ -75,7 +75,8 @@ namespace InABox.Core
|
|
{
|
|
{
|
|
private Expression Expression;
|
|
private Expression Expression;
|
|
|
|
|
|
- public bool IsValid {
|
|
|
|
|
|
+ public bool IsValid
|
|
|
|
+ {
|
|
get
|
|
get
|
|
{
|
|
{
|
|
try
|
|
try
|
|
@@ -89,6 +90,8 @@ namespace InABox.Core
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public string ExpressionString { get; set; }
|
|
|
|
+
|
|
public IReadOnlyCollection<string> ReferencedVariables => Expression.ReferencedVariables;
|
|
public IReadOnlyCollection<string> ReferencedVariables => Expression.ReferencedVariables;
|
|
|
|
|
|
protected virtual Type? ReturnType { get; }
|
|
protected virtual Type? ReturnType { get; }
|
|
@@ -96,6 +99,7 @@ namespace InABox.Core
|
|
public CoreExpression(string expressionString, Type? returnType = null)
|
|
public CoreExpression(string expressionString, Type? returnType = null)
|
|
{
|
|
{
|
|
Expression = new Expression(expressionString, _context);
|
|
Expression = new Expression(expressionString, _context);
|
|
|
|
+ ExpressionString = expressionString;
|
|
ReturnType = returnType;
|
|
ReturnType = returnType;
|
|
if (!IsValid)
|
|
if (!IsValid)
|
|
{
|
|
{
|
|
@@ -127,6 +131,17 @@ namespace InABox.Core
|
|
}
|
|
}
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ [return: MaybeNull]
|
|
|
|
+ public T Evaluate<T>(IVariableProvider provider)
|
|
|
|
+ {
|
|
|
|
+ var result = Evaluate(provider);
|
|
|
|
+ if(result is T ret)
|
|
|
|
+ {
|
|
|
|
+ return ret;
|
|
|
|
+ }
|
|
|
|
+ return default;
|
|
|
|
+ }
|
|
public Result<T, Exception> TryEvaluate<T>(IVariableProvider provider)
|
|
public Result<T, Exception> TryEvaluate<T>(IVariableProvider provider)
|
|
{
|
|
{
|
|
try
|
|
try
|