Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DictionarySubtraction.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 ((Left is IEnumerable<KeyValuePair<string, IElement>> ||
36 Left is IEnumerable<KeyValuePair<string, object>>) &&
37 (Right is IEnumerable<KeyValuePair<string, IElement>> ||
38 Right is IEnumerable<KeyValuePair<string, object>>))
39 {
40 return Grade.Excellent;
41 }
42 else
43 return Grade.NotAtAll;
44 }
45
53 {
54 Dictionary<string, IElement> Result = new Dictionary<string, IElement>();
55 object L = Operation.Left.AssociatedObjectValue;
56 object R = Operation.Right.AssociatedObjectValue;
57
58 if (L is IDictionary<string, IElement> LeftDictionary)
59 {
60 foreach (KeyValuePair<string, IElement> P in LeftDictionary)
61 Result[P.Key] = P.Value;
62 }
63 else if (L is IDictionary<string, object> LeftDictionary2)
64 {
65 foreach (KeyValuePair<string, object> P in LeftDictionary2)
66 Result[P.Key] = Expression.Encapsulate(P.Value);
67 }
68 else if (L is IEnumerable<KeyValuePair<string, IElement>> LeftEnumeration)
69 {
70 foreach (KeyValuePair<string, IElement> P in LeftEnumeration)
71 {
72 if (Result.TryGetValue(P.Key, out IElement E))
73 Result[P.Key] = Add.EvaluateAddition(E, P.Value, Node);
74 else
75 Result[P.Key] = P.Value;
76 }
77 }
78 else if (L is IEnumerable<KeyValuePair<string, object>> LeftEnumeration2)
79 {
80 foreach (KeyValuePair<string, object> P in LeftEnumeration2)
81 {
82 IElement Value = Expression.Encapsulate(P.Value);
83
84 if (Result.TryGetValue(P.Key, out IElement E))
85 Result[P.Key] = Add.EvaluateAddition(E, Value, Node);
86 else
87 Result[P.Key] = Value;
88 }
89 }
90
91 if (R is IDictionary<string, IElement> RightDictionary)
92 {
93 foreach (KeyValuePair<string, IElement> P in RightDictionary)
94 {
95 if (Result.TryGetValue(P.Key, out IElement E))
96 Result[P.Key] = Subtract.EvaluateSubtraction(E, P.Value, Node);
97 else
98 Result[P.Key] = Negate.EvaluateNegation(P.Value);
99 }
100 }
101 else if (R is IDictionary<string, object> RightDictionary2)
102 {
103 foreach (KeyValuePair<string, object> P in RightDictionary2)
104 {
105 IElement Value = Expression.Encapsulate(P.Value);
106
107 if (Result.TryGetValue(P.Key, out IElement E))
108 Result[P.Key] = Subtract.EvaluateSubtraction(E, Value, Node);
109 else
110 Result[P.Key] = Negate.EvaluateNegation(Value);
111 }
112 }
113 else if (R is IEnumerable<KeyValuePair<string, IElement>> RightEnumeration)
114 {
115 foreach (KeyValuePair<string, IElement> P in RightEnumeration)
116 {
117 if (Result.TryGetValue(P.Key, out IElement E))
118 Result[P.Key] = Subtract.EvaluateSubtraction(E, P.Value, Node);
119 else
120 Result[P.Key] = Negate.EvaluateNegation(P.Value);
121 }
122 }
123 else if (R is IEnumerable<KeyValuePair<string, object>> RightEnumeration2)
124 {
125 foreach (KeyValuePair<string, object> P in RightEnumeration2)
126 {
127 IElement Value = Expression.Encapsulate(P.Value);
128
129 if (Result.TryGetValue(P.Key, out IElement E))
130 Result[P.Key] = Subtract.EvaluateSubtraction(E, Value, Node);
131 else
132 Result[P.Key] = Negate.EvaluateNegation(Value);
133 }
134 }
135
136 return new ObjectValue(Result);
137 }
138 }
139}
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
static IElement EvaluateAddition(IElement Left, IElement Right, ScriptNode Node)
Adds two operands.
Definition: Add.cs:65
IElement Evaluate(IBinaryOperation Operation, ScriptNode Node)
Evaluates the custom binary operator.
Grade Supports(IBinaryOperation Operation)
How well the operator supports the given types of operands.
DictionarySubtraction()
Performs subtraction of two dictionaries.
static IElement EvaluateNegation(IElement Operand)
Negates an object.
Definition: Negate.cs:54
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
Grade
Grade enumeration
Definition: Grade.cs:7