2using System.Collections.Generic;
3using System.Reflection;
4using System.Threading.Tasks;
77 else if (Vector is
ISet S)
106 Type T = Object.GetType();
107 if (!
TryGetIndexProperty(T,
true,
false, out PropertyInfo ItemProperty, out ParameterInfo[] Parameters))
110 return await
EvaluateIndex(Object, T, ItemProperty, Parameters, Index, Node);
115 LinkedList<IElement> Elements =
new LinkedList<IElement>();
118 Elements.AddLast(await
EvaluateIndex(E, Index, NullCheck, Node));
133 public static bool TryGetIndexProperty(Type T,
bool ForReading,
bool ForWriting, out PropertyInfo PropertyInfo, out ParameterInfo[] Parameters)
135 lock (indexProperties)
137 if (indexProperties.TryGetValue(T, out KeyValuePair<PropertyInfo, ParameterInfo[]> P))
139 PropertyInfo = P.Key;
140 Parameters = P.Value;
144 foreach (PropertyInfo P2
in T.GetRuntimeProperties())
146 if (P2.Name !=
"Item")
149 if (ForReading && (!P2.CanRead || !P2.GetMethod.IsPublic))
152 if (ForWriting && (!P2.CanWrite || !P2.SetMethod.IsPublic))
155 Parameters = P2.GetIndexParameters();
156 if (Parameters is
null || Parameters.Length != 1)
159 indexProperties[T] =
new KeyValuePair<PropertyInfo, ParameterInfo[]>(P2, Parameters);
172 private static readonly Dictionary<Type, KeyValuePair<PropertyInfo, ParameterInfo[]>> indexProperties =
new Dictionary<Type, KeyValuePair<PropertyInfo, ParameterInfo[]>>();
174 private static async Task<IElement>
EvaluateIndex(
object Object, Type T, PropertyInfo ItemProperty, ParameterInfo[] Parameters,
177 if (Index.
TryConvertTo(Parameters[0].ParameterType, out
object IndexValue))
179 object Result = await
WaitPossibleTask(ItemProperty.GetValue(Object,
new object[] { IndexValue }));
186 LinkedList<IElement> Elements =
new LinkedList<IElement>();
189 Elements.AddLast(await
EvaluateIndex(Object, T, ItemProperty, Parameters, E, Node));
203 LinkedList<IElement> Elements =
new LinkedList<IElement>();
223 if (d < 0 || d >
int.MaxValue || d != Math.Truncate(d))
233 LinkedList<IElement> Elements =
new LinkedList<IElement>();
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(ICollection< 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.