Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
DictionaryRightScalarAddition.cs
7
9{
14 {
19 {
20 }
21
28 {
29 if (Operation.Name != "op_Addition")
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 Operation.Right.IsScalar &&
38 !(Right is IEnumerable<KeyValuePair<string, IElement>> ||
39 Right 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 L = Operation.Left.AssociatedObjectValue;
57 IElement Scalar = Operation.Right;
58
59 if (L is IDictionary<string, IElement> LeftDictionary)
60 {
61 foreach (KeyValuePair<string, IElement> P in LeftDictionary)
62 Result[P.Key] = Add.EvaluateAddition(P.Value, Scalar, Node);
63 }
64 else if (L is IDictionary<string, object> LeftDictionary2)
65 {
66 foreach (KeyValuePair<string, object> P in LeftDictionary2)
67 Result[P.Key] = Add.EvaluateAddition(Expression.Encapsulate(P.Value), Scalar, Node);
68 }
69 else if (L is IEnumerable<KeyValuePair<string, IElement>> LeftEnumeration)
70 {
71 foreach (KeyValuePair<string, IElement> P in LeftEnumeration)
72 {
73 if (Result.TryGetValue(P.Key, out IElement E))
74 Result[P.Key] = Add.EvaluateAddition(E, P.Value, Node);
75 else
76 Result[P.Key] = Add.EvaluateAddition(P.Value, Scalar, Node);
77 }
78 }
79 else if (L is IEnumerable<KeyValuePair<string, object>> LeftEnumeration2)
80 {
81 foreach (KeyValuePair<string, object> P in LeftEnumeration2)
82 {
83 IElement Value = Expression.Encapsulate(P.Value);
84
85 if (Result.TryGetValue(P.Key, out IElement E))
86 Result[P.Key] = Add.EvaluateAddition(E, Value, Node);
87 else
88 Result[P.Key] = Add.EvaluateAddition(Value, Scalar, 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
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.
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