Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Inherits.cs
1using System;
2using System.Reflection;
3using System.Threading.Tasks;
8
10{
15 {
25 : base(Left, Right, Start, Length, Expression)
26 {
27 }
28
36 public override IElement Evaluate(IElement Left, IElement Right, Variables Variables)
37 {
38 if (Right is TypeValue TypeValue)
39 return this.EvaluateInherits(Left, TypeValue);
40 else
41 return base.Evaluate(Left, Right, Variables);
42 }
43
44 private BooleanValue EvaluateInherits(IElement Left, TypeValue Right)
45 {
46 Type Expected = Right.Value;
47 object Obj = Left.AssociatedObjectValue;
48
49 if (!(Obj is Type Candidate))
50 Candidate = Obj?.GetType() ?? typeof(object);
51
52 if (Expected.GetTypeInfo().IsAssignableFrom(Candidate.GetTypeInfo()))
53 return BooleanValue.True;
54 else
55 return BooleanValue.False;
56 }
57
65 public override Task<IElement> EvaluateAsync(IElement Left, IElement Right, Variables Variables)
66 {
67 if (Right is TypeValue TypeValue)
68 return Task.FromResult<IElement>(this.EvaluateInherits(Left, TypeValue));
69 else
70 return base.EvaluateAsync(Left, Right, Variables);
71 }
72
81 {
82 if (Right is TypeValue TypeValue)
83 return this.EvaluateInherits(Left, TypeValue);
84 else
85 throw new ScriptRuntimeException("Right operand in an INHERITS operation must be a type value.", this);
86 }
87
95 public override Task<IElement> EvaluateScalarAsync(IElement Left, IElement Right, Variables Variables)
96 {
97 if (Right is TypeValue TypeValue)
98 return Task.FromResult<IElement>(this.EvaluateInherits(Left, TypeValue));
99 else
100 throw new ScriptRuntimeException("Right operand in an INHERITS operation must be a type value.", this);
101 }
102
106 public override UpgradeBehaviour ScalarUpgradeBehaviour => UpgradeBehaviour.DifferentTypesOk;
107 }
108}
Class managing a script expression.
Definition: Expression.cs:39
Base class for binary scalar operators.
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
Boolean-valued number.
Definition: BooleanValue.cs:12
static readonly BooleanValue False
Constant false value.
static readonly BooleanValue True
Constant true value.
override UpgradeBehaviour ScalarUpgradeBehaviour
How scalar operands of different types are to be treated. By default, scalar operands are required to...
Definition: Inherits.cs:106
override Task< IElement > EvaluateScalarAsync(IElement Left, IElement Right, Variables Variables)
Evaluates the operator on scalar operands.
Definition: Inherits.cs:95
override Task< IElement > EvaluateAsync(IElement Left, IElement Right, Variables Variables)
Evaluates the operator.
Definition: Inherits.cs:65
Inherits(ScriptNode Left, ScriptNode Right, int Start, int Length, Expression Expression)
Inherits operator.
Definition: Inherits.cs:24
override IElement EvaluateScalar(IElement Left, IElement Right, Variables Variables)
Evaluates the operator on scalar operands.
Definition: Inherits.cs:80
override IElement Evaluate(IElement Left, IElement Right, Variables Variables)
Evaluates the operator.
Definition: Inherits.cs:36
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
UpgradeBehaviour
How operands are to be handled if not of the same type.