3using System.Reflection;
4using System.Threading.Tasks;
78 else if (Vector is
ISet S)
107 Type T = Object.GetType();
109 out ParameterInfo[] Parameters) ||
110 (Parameters?.
Length ?? 0) != 1)
115 return await
EvaluateIndex(Object, T, ItemProperty, Parameters, Index, Node);
123 Elements.Add(await
EvaluateIndex(E, Index, NullCheck, Node));
139 out PropertyInfo PropertyInfo, out ParameterInfo[] Parameters)
141 lock (indexProperties)
143 if (indexProperties.TryGetValue(T, out KeyValuePair<PropertyInfo, ParameterInfo[]> P))
145 PropertyInfo = P.Key;
146 Parameters = P.Value;
150 foreach (PropertyInfo P2
in T.GetRuntimeProperties())
152 if (P2.Name !=
"Item")
155 if (ForReading && (!P2.CanRead || !P2.GetMethod.IsPublic))
158 if (ForWriting && (!P2.CanWrite || !P2.SetMethod.IsPublic))
161 Parameters = P2.GetIndexParameters();
162 if (Parameters is
null || Parameters.Length != 1)
165 indexProperties[T] =
new KeyValuePair<PropertyInfo, ParameterInfo[]>(P2, Parameters);
178 private static readonly Dictionary<Type, KeyValuePair<PropertyInfo, ParameterInfo[]>> indexProperties =
new Dictionary<Type, KeyValuePair<PropertyInfo, ParameterInfo[]>>();
180 internal static async Task<IElement>
EvaluateIndex(
object Object, Type T, PropertyInfo ItemProperty, ParameterInfo[] Parameters,
183 if (Index.
TryConvertTo(Parameters[0].ParameterType, out
object IndexValue))
185 object Result = await
WaitPossibleTask(ItemProperty.GetValue(Object,
new object[] { IndexValue }));
195 Elements.
Add(await
EvaluateIndex(Object, T, ItemProperty, Parameters, E, Node));
229 if (d < 0 || d >
int.MaxValue || d != Math.Truncate(d))
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
Exception thrown if an operand is out of bounds.
Script runtime exception.
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
static double ToDouble(object Object)
Converts an object to a double value.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
Base class for all unary operators performing operand null checks.
readonly bool nullCheck
If null should be returned if operand is null.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
static async Task< object > WaitPossibleTask(object Result)
Waits for any asynchronous process to terminate.
int Start
Start position in script expression.
abstract IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
string Value
String value.
bool CaseInsensitive
If the string value is case insensitive or not.
static async Task< IElement > EvaluateIndex(IElement Vector, IElement Index, bool NullCheck, ScriptNode Node)
Evaluates the vector index operator.
static IElement EvaluateIndex(IVector Vector, IElement Index, ScriptNode Node)
Evaluates the vector index operator.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
static bool TryGetIndexProperty(Type T, bool ForReading, bool ForWriting, out PropertyInfo PropertyInfo, out ParameterInfo[] Parameters)
Tries to get a one-dimensional index property of a Type.
VectorIndex(ScriptNode Left, ScriptNode Right, bool NullCheck, int Start, int Length, Expression Expression)
Vector Index operator.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Basic interface for all types of elements.
bool TryConvertTo(Type DesiredType, out object Value)
Converts the value to a .NET type.
object AssociatedObjectValue
Associated object value.
ICollection< IElement > ChildElements
An enumeration of child elements. If the element is a scalar, this property will return null.
IElement Encapsulate(ChunkedList< IElement > Elements, ScriptNode Node)
Encapsulates a set of elements into a similar structure as that provided by the current element.
bool IsScalar
If the element represents a scalar value.
Basic interface for vectors.
IElement GetElement(int Index)
Gets an element of the vector.
Basic interface for all types of sets.