2using System.Reflection;
3using System.Runtime.ExceptionServices;
5using System.Threading.Tasks;
22 private readonly
string name;
43 public string Name => this.name;
70 object Value =
Operand.AssociatedObjectValue;
82 T = Value?.GetType() ?? typeof(
object);
87 await this.synchObject.WaitAsync();
96 this.nameIndex =
null;
97 this.property = T.GetRuntimeProperty(this.name);
99 if (this.property is
null)
101 this.field = T.GetRuntimeField(this.name);
102 if (this.field is
null)
104 this._event = T.GetRuntimeEvent(this.name);
105 if (this._event is
null)
109 foreach (MethodInfo MI
in T.GetRuntimeMethods())
111 if (!MI.IsAbstract && MI.IsPublic && MI.Name ==
this.name)
120 this.methods =
Methods?.ToArray();
121 if (this.methods is
null)
124 out ParameterInfo[] IndexArguments) &&
125 (IndexArguments?.Length ?? 0) == 1)
127 if (IndexArguments[0].ParameterType == typeof(
string))
128 this.nameIndex =
new object[] { this.name };
130 this.nameIndex =
new object[] {
Expression.
ConvertTo(this.name, IndexArguments[0].ParameterType,
this) };
136 if (!this._event.AddMethod.IsPublic)
142 if (!this.field.IsPublic)
148 if (!this.property.CanRead)
150 else if (!this.property.GetMethod.IsPublic)
155 object Result =
null;
157 if (!(this.property is
null))
161 Result = await
WaitPossibleTask(this.property.GetValue(Instance,
this.nameIndex));
165 if (Instance is
null)
166 Result = this.property;
168 ExceptionDispatchInfo.Capture(ex).Throw();
173 else if (!(this.field is
null))
181 if (Instance is
null)
184 ExceptionDispatchInfo.Capture(ex).Throw();
189 else if (!(this._event is
null))
191 else if (!(this.methods is
null))
193 if (this.methods.Length == 1)
199 throw new ScriptRuntimeException(
"Member '" + this.name +
"' not found on type '" + T.FullName +
"'.",
this);
203 this.synchObject.Release();
211 return Operand.Encapsulate(Elements,
this);
214 private Type type =
null;
215 private PropertyInfo
property =
null;
216 private FieldInfo field =
null;
217 private EventInfo _event =
null;
219 private object[] nameIndex =
null;
220 private readonly SemaphoreSlim synchObject =
new SemaphoreSlim(1);
222 internal static readonly Type[] stringType =
new Type[] { typeof(
string) };
234 object Value =
Operand.AssociatedObjectValue;
250 PropertyInfo Property = T.GetRuntimeProperty(
Name);
251 if (!(Property is
null))
253 if (!Property.CanRead)
255 else if (!Property.GetMethod.IsPublic)
261 FieldInfo Field = T.GetRuntimeField(
Name);
262 if (!(Field is
null))
270 EventInfo Event = T.GetRuntimeEvent(
Name);
271 if (!(Event is
null))
276 foreach (MethodInfo MI
in T.GetRuntimeMethods())
278 if (!MI.IsAbstract && MI.IsPublic && MI.Name ==
Name)
296 out ParameterInfo[] IndexArguments) &&
297 (IndexArguments?.Length ?? 0) == 1)
301 if (IndexArguments[0].ParameterType == typeof(
string))
302 Index =
new object[] {
Name };
317 return Operand.Encapsulate(Elements, Node);
A chunked list is a linked list of chunks of objects of type T .
Script runtime exception.
Class managing a script expression.
static IElement Encapsulate(object Value)
Encapsulates an object.
static object ConvertTo(IElement Value, Type DesiredType, ScriptNode Node)
Tries to conevert an element value to a desired type.
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.