Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UnaryBooleanOperator.cs
1using System;
2using System.Threading.Tasks;
6
7namespace Waher.Script.Model
8{
13 {
23 {
24 }
25
32 {
33 IElement Op = this.op.Evaluate(Variables);
34
35 if (Op.AssociatedObjectValue is bool BOp)
36 return this.Evaluate(BOp);
37 else
38 return this.Evaluate(Op, Variables);
39 }
40
46 public override async Task<IElement> EvaluateAsync(Variables Variables)
47 {
48 if (!this.isAsync)
49 return base.Evaluate(Variables);
50
51 IElement Op = await this.op.EvaluateAsync(Variables);
52
53 if (Op.AssociatedObjectValue is bool BOp)
54 return await this.EvaluateAsync(BOp);
55 else
56 return await this.EvaluateAsync(Op, Variables);
57 }
58
66 {
67 object Obj = Operand.AssociatedObjectValue;
68
69 if (Obj is bool BOp)
70 return this.Evaluate(BOp);
71 else if (Expression.TryConvert(Obj, out bool b))
72 return this.Evaluate(b);
73 else
74 throw new ScriptRuntimeException("Scalar operands must be boolean values.", this);
75 }
76
83 public override async Task<IElement> EvaluateScalarAsync(IElement Operand, Variables Variables)
84 {
85 object Obj = Operand.AssociatedObjectValue;
86
87 if (Obj is bool BOp)
88 return await this.EvaluateAsync(BOp);
89 else if (Expression.TryConvert(Obj, out bool b))
90 return await this.EvaluateAsync(b);
91 else
92 throw new ScriptRuntimeException("Scalar operands must be boolean values.", this);
93 }
94
100 public abstract IElement Evaluate(bool Operand);
101
107 public virtual Task<IElement> EvaluateAsync(bool Operand)
108 {
109 return Task.FromResult<IElement>(this.Evaluate(Operand));
110 }
111
112 }
113}
Class managing a script expression.
Definition: Expression.cs:39
static bool TryConvert(object Value, Type DesiredType, out object Result)
Tries to convert an object Value to an object of type DesiredType .
Definition: Expression.cs:5268
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Definition: ScriptNode.cs:158
Base class for unary boolean operators.
override IElement EvaluateScalar(IElement Operand, Variables Variables)
Evaluates the operator on scalar operands.
UnaryBooleanOperator(ScriptNode Operand, int Start, int Length, Expression Expression)
Base class for binary boolean operators.
virtual Task< IElement > EvaluateAsync(bool Operand)
Evaluates the boolean operator.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override async Task< IElement > EvaluateScalarAsync(IElement Operand, Variables Variables)
Evaluates the operator on scalar operands.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
abstract IElement Evaluate(bool Operand)
Evaluates the boolean operator.
bool isAsync
If subtree is asynchroneous.
Base class for unary scalar operators.
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:20
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:33