You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
922 B
32 lines
922 B
2 years ago
|
using EC.Helper.RabbitFunc.Runtime;
|
||
|
|
||
|
namespace EC.Helper.RabbitFunc.Expressions;
|
||
|
|
||
|
public class ConditionalExpression : Expression
|
||
|
{
|
||
|
internal ConditionalExpression(Expression test, Expression trueExpression, Expression falseExpression)
|
||
|
: base(ExpressionType.MethodCall)
|
||
|
{
|
||
|
Test = test;
|
||
|
TrueExpression = trueExpression;
|
||
|
FalseExpression = falseExpression;
|
||
|
}
|
||
|
|
||
|
public override ExpressionType NodeType => ExpressionType.Conditional;
|
||
|
|
||
|
public Expression Test { get; }
|
||
|
|
||
|
public Expression TrueExpression { get; }
|
||
|
|
||
|
public Expression FalseExpression { get; }
|
||
|
|
||
|
public override object Eval(RuntimeContext context)
|
||
|
{
|
||
|
return (bool)Test.Eval(context) ? TrueExpression.Eval(context) : FalseExpression.Eval(context);
|
||
|
}
|
||
|
|
||
|
public override string ToString()
|
||
|
{
|
||
|
return string.Format("if({0},{1},{2})", Test, TrueExpression, FalseExpression);
|
||
|
}
|
||
|
}
|