Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DictionaryLeftScalarSubtraction.cs
7
9{
14 {
19 {
20 }
21
28 {
29 if (Operation.Name != "op_Subtraction")
30 return Grade.NotAtAll;
31
32 object Left = Operation.Left.AssociatedObjectValue;
33 object Right = Operation.Right.AssociatedObjectValue;
34
35 if ((Right is IEnumerable<KeyValuePair<string, IElement>> ||
36 Right is IEnumerable<KeyValuePair<string, object>>) &&
37 Operation.Left.IsScalar &&
38 !(Left is IEnumerable<KeyValuePair<string, IElement>> ||
39 Left is IEnumerable<KeyValuePair<string, object>>))
40 {
41 return Grade.Excellent;
42 }
43 else
44 return Grade.NotAtAll;
45 }
46
54 {
55 Dictionary<string, IElement> Result = new Dictionary<string, IElement>();
56 object R = Operation.Right.AssociatedObjectValue;
57 IElement Scalar = Operation.Left;
58
59 if (R is IDictionary<string, IElement> RightDictionary)
60 {
61 foreach (KeyValuePair<string, IElement> P in RightDictionary)
62 Result[P.Key] = Subtract.EvaluateSubtraction(Scalar, P.Value, Node);
63 }
64 else if (R is IDictionary<string, object> RightDictionary2)
65 {
66 foreach (KeyValuePair<string, object> P in RightDictionary2)
67 Result[P.Key] = Subtract.EvaluateSubtraction(Scalar, Expression.Encapsulate(P.Value), Node);
68 }
69 else if (R is IEnumerable<KeyValuePair<string, IElement>> RightEnumeration)
70 {
71 foreach (KeyValuePair<string, IElement> P in RightEnumeration)
72 {
73 if (Result.TryGetValue(P.Key, out IElement E))
74 Result[P.Key] = Subtract.EvaluateSubtraction(E, P.Value, Node);
75 else
76 Result[P.Key] = Subtract.EvaluateSubtraction(Scalar, P.Value, Node);
77 }
78 }
79 else if (R is IEnumerable<KeyValuePair<string, object>> RightEnumeration2)
80 {
81 foreach (KeyValuePair<string, object> P in RightEnumeration2)
82 {
83 IElement Value = Expression.Encapsulate(P.Value);
84
85 if (Result.TryGetValue(P.Key, out IElement E))
86 Result[P.Key] = Subtract.EvaluateSubtraction(E, Value, Node);
87 else
88 Result[P.Key] = Subtract.EvaluateSubtraction(Scalar, Value, Node);
89 }
90 }
91
92 return new ObjectValue(Result);
93 }
94 }
95}
Class managing a script expression.
Definition: Expression.cs:41
static IElement Encapsulate(object Value)
Encapsulates an object.
Definition: Expression.cs:5241
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
Grade Supports(IBinaryOperation Operation)
How well the operator supports the given types of operands.
DictionaryLeftScalarSubtraction()
Performs subtraction of a scalar and a dictionary.
IElement Evaluate(IBinaryOperation Operation, ScriptNode Node)
Evaluates the custom binary operator.
static IElement EvaluateSubtraction(IElement Left, IElement Right, ScriptNode Node)
Subtracts the right operand from the left one.
Definition: Subtract.cs:65
Basic interface for all types of elements.
Definition: IElement.cs:21
object AssociatedObjectValue
Associated object value.
Definition: IElement.cs:34
bool IsScalar
If the element represents a scalar value.
Definition: IElement.cs:42
Grade
Grade enumeration
Definition: Grade.cs:7