2using System.Collections.Generic;
14 private readonly
object[] objects;
16 private readonly Dictionary<string, object> groupedValues =
new Dictionary<string, object>();
17 private readonly
int objectCount;
18 private readonly
int groupCount;
35 this.objectCount = this.objects.Length;
36 this.groupCount = GroupNames.
Length;
37 if (GroupByValues.Length !=
this.groupCount)
38 throw new ArgumentException(
"Length mismatch.", nameof(GroupByValues));
44 for (i = 0; i < this.groupCount; i++)
51 Name = Ref.VariableName;
58 if (!
string.IsNullOrEmpty(Name))
59 this.groupedValues[Name] = GroupByValues[i];
68 public object this[
string Name]
72 if (this.groupedValues.TryGetValue(Name, out
object Value))
75 if (this.objectCount == 1)
78 object Item = this.objects[0];
84 if (this.properties is
null)
87 this.properties.Object = Item;
95 this.groupedValues[Name] = Result;
101 Type ItemType =
null;
103 object[] Result =
new object[this.objectCount];
107 for (i = 0; i < this.objectCount; i++)
109 Item = this.objects[i];
118 if (this.properties is
null)
121 this.properties.Object = Item;
123 if (this.properties.
TryGetValue(Name, out Value) && !(Value is
null))
128 else if (T != ItemType)
141 if (ItemType == typeof(
double))
143 double[] TypedArray =
new double[this.objectCount];
144 Array.Copy(Result, 0, TypedArray, 0, this.objectCount);
147 else if (ItemType == typeof(
bool))
149 bool[] TypedArray =
new bool[this.objectCount];
150 Array.Copy(Result, 0, TypedArray, 0, this.objectCount);
153 else if (ItemType == typeof(
string))
155 string[] TypedArray =
new string[this.objectCount];
156 Array.Copy(Result, 0, TypedArray, 0, this.objectCount);
159 else if (ItemType == typeof(DateTime))
161 DateTime[] TypedArray =
new DateTime[this.objectCount];
162 Array.Copy(Result, 0, TypedArray, 0, this.objectCount);
165 else if (ItemType == typeof(Complex))
167 Complex[] TypedArray =
new Complex[this.objectCount];
168 Array.Copy(Result, 0, TypedArray, 0, this.objectCount);
173 this.groupedValues[Name] = Result;
181 this.groupedValues[Name] = value;
188 public int Count => this.objects.Length;
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Represents a variable reference.
Represents a collection of objects grouped together useing a GROUP BY construct.
GroupObject(object[] Objects, object[] GroupByValues, ScriptNode[] GroupNames, Variables Variables)
Represents a collection of objects grouped together useing a GROUP BY construct.
object[] Objects
Objects in group.
int Count
Number of objects in group.
bool TryGetValue(string Name, out object Value)
Tries to get the value, given its variable name.
Basic interface for all types of elements.
object AssociatedObjectValue
Associated object value.