2using System.Reflection;
3using System.Threading.Tasks;
18 private readonly
string name;
37 public string Name => this.name;
70 object LeftValue =
Left.AssociatedObjectValue;
71 Type Type = LeftValue.GetType();
73 lock (this.synchObject)
75 if (Type != this.type)
78 this.property = Type.GetRuntimeProperty(this.name);
79 if (!(this.property is
null))
82 this.nameIndex =
null;
84 if (!this.property.CanWrite)
86 else if (!this.property.SetMethod.IsPublic)
91 this.field = Type.GetRuntimeField(this.name);
92 if (!(this.field is
null))
94 this.nameIndex =
null;
96 if (!this.field.IsPublic)
102 out ParameterInfo[] IndexArguments) &&
103 (IndexArguments?.Length ?? 0) == 1)
105 if (this.nameIndex is
null)
107 if (IndexArguments[0].ParameterType == typeof(
string))
108 this.nameIndex =
new string[] { this.name };
110 this.nameIndex =
new object[] {
Expression.
ConvertTo(this.name, IndexArguments[0].ParameterType,
this) };
114 this.nameIndex =
null;
119 if (!(this.property is
null))
121 Type = this.
property.PropertyType;
122 if (Type == typeof(
object))
123 this.
property.SetValue(LeftValue,
Right.AssociatedObjectValue,
this.nameIndex);
124 else if (Type.IsAssignableFrom(
Right.GetType().GetTypeInfo()))
125 this.
property.SetValue(LeftValue,
Right, this.nameIndex);
129 else if (!(this.field is
null))
131 Type = this.field.FieldType;
132 if (!Type.IsAssignableFrom(
Right.GetType().GetTypeInfo()))
138 throw new ScriptRuntimeException(
"Member '" + this.name +
"' not found on type '" + Type.FullName +
"'.",
this);
144 private Type type =
null;
145 private PropertyInfo
property =
null;
146 private FieldInfo field =
null;
147 private object[] nameIndex =
null;
148 private readonly
object synchObject =
new object();
Script runtime exception.
Class managing a script expression.
static object ConvertTo(IElement Value, Type DesiredType, ScriptNode Node)
Tries to conevert an element value to a desired type.
Base class for all binary operators.
ScriptNode right
Right operand.
ScriptNode left
Left operand.
bool isAsync
If subtree is asynchroneous.
Base class for all nodes in a parsed script tree.
int Length
Length of expression covered by node.
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 ...
virtual Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection. This method should be ...
Named member Assignment operator.
override async Task< IElement > EvaluateAsync(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
NamedMemberAssignment(NamedMember NamedMember, ScriptNode Operand, int Start, int Length, Expression Expression)
Named member Assignment operator.
override IElement Evaluate(Variables Variables)
Evaluates the node, using the variables provided in the Variables collection.
string Name
Name of method.
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.