2using System.Reflection;
3using System.Collections.Generic;
4using System.Runtime.ExceptionServices;
5using System.Threading.Tasks;
12using System.Threading;
21 private readonly
string name;
42 public string Name => this.name;
69 object Value =
Operand.AssociatedObjectValue;
81 T = Value?.GetType() ?? typeof(
object);
86 await this.synchObject.WaitAsync();
95 this.nameIndex =
null;
96 this.property = T.GetRuntimeProperty(this.name);
98 if (this.property is
null)
100 this.field = T.GetRuntimeField(this.name);
101 if (this.field is
null)
103 this._event = T.GetRuntimeEvent(this.name);
104 if (this._event is
null)
106 List<MethodLambda>
Methods =
null;
108 foreach (MethodInfo MI
in T.GetRuntimeMethods())
110 if (!MI.IsAbstract && MI.IsPublic && MI.Name ==
this.name)
113 Methods =
new List<MethodLambda>();
119 this.methods =
Methods?.ToArray();
120 if (this.methods is
null)
123 this.nameIndex =
new string[] { this.name };
128 if (!this._event.AddMethod.IsPublic)
134 if (!this.field.IsPublic)
140 if (!this.property.CanRead)
142 else if (!this.property.GetMethod.IsPublic)
147 object Result =
null;
149 if (!(this.property is
null))
153 if (!(this.nameIndex is
null))
154 Result = await
WaitPossibleTask(this.property.GetValue(Instance,
this.nameIndex));
160 if (Instance is
null)
161 Result = this.property;
163 ExceptionDispatchInfo.Capture(ex).Throw();
168 else if (!(this.field is
null))
176 if (Instance is
null)
179 ExceptionDispatchInfo.Capture(ex).Throw();
184 else if (!(this._event is
null))
186 else if (!(this.methods is
null))
188 if (this.methods.Length == 1)
194 throw new ScriptRuntimeException(
"Member '" + this.name +
"' not found on type '" + T.FullName +
"'.",
this);
198 this.synchObject.Release();
201 LinkedList<IElement> Elements =
new LinkedList<IElement>();
206 return Operand.Encapsulate(Elements,
this);
209 private Type type =
null;
210 private PropertyInfo
property =
null;
211 private FieldInfo field =
null;
212 private EventInfo _event =
null;
214 private string[] nameIndex =
null;
215 private readonly SemaphoreSlim synchObject =
new SemaphoreSlim(1);
217 internal static readonly Type[] stringType =
new Type[] { typeof(
string) };
229 object Value =
Operand.AssociatedObjectValue;
245 PropertyInfo Property = T.GetRuntimeProperty(
Name);
246 if (!(Property is
null))
248 if (!Property.CanRead)
250 else if (!Property.GetMethod.IsPublic)
256 FieldInfo Field = T.GetRuntimeField(
Name);
257 if (!(Field is
null))
265 EventInfo Event = T.GetRuntimeEvent(
Name);
266 if (!(Event is
null))
269 List<MethodLambda>
Methods =
null;
271 foreach (MethodInfo MI
in T.GetRuntimeMethods())
273 if (!MI.IsAbstract && MI.IsPublic && MI.Name ==
Name)
276 Methods =
new List<MethodLambda>();
296 LinkedList<IElement> Elements =
new LinkedList<IElement>();
301 return Operand.Encapsulate(Elements, Node);
Script runtime exception.
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
Lambda expression executing object methods.
Extract the methods of a type or an object.
Base class for all unary operators performing operand null checks.
bool NullCheck
If null check is to be used.
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.
ScriptNode Operand
Operand.
static readonly ObjectValue Null
Null value.
override IElement Evaluate(IElement Operand, Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override async Task< IElement > EvaluateAsync(IElement Operand, Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
string Name
Name of method.
NamedMember(ScriptNode Operand, string Name, bool NullCheck, int Start, int Length, Expression Expression)
Named member operator
static async Task< IElement > EvaluateDynamic(IElement Operand, string Name, bool NullCheck, ScriptNode Node)
Evaluates the member operator dynamically on an operand.
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.
Basic interface for all types of elements.