3using System.Reflection;
17 private readonly Dictionary<string, PropertyRecord> properties =
new Dictionary<string, PropertyRecord>();
18 private readonly Type leftType;
19 private readonly Type rightType;
22 private readonly
object left;
23 private readonly
object right;
24 private readonly
string leftName;
25 private readonly
string rightName;
26 private readonly
bool hasLeftName;
27 private readonly
bool hasRightName;
28 private readonly
bool isLeftGen;
29 private readonly
bool isRightGen;
30 private string objectId =
null;
39 public JoinedObject(
object Left,
string LeftName,
object Right,
string RightName)
43 this.leftType = this.left?.GetType();
44 this.leftName = LeftName;
45 this.hasLeftName = !
string.IsNullOrEmpty(this.leftName);
46 this.isLeftGen = !(this.leftGen is
null);
49 this.rightType = this.right?.GetType();
50 this.rightName = RightName;
51 this.hasRightName = !
string.IsNullOrEmpty(this.rightName);
52 this.isRightGen = !(this.rightGen is
null);
60 public object this[
string Index]
64 if (this.isLeftGen && this.leftGen.TryGetFieldValue(Index, out
object Value))
66 else if (this.isRightGen && this.rightGen.TryGetFieldValue(Index, out Value))
68 else if (this.hasLeftName &&
string.Compare(Index, this.leftName,
true) == 0)
70 else if (this.hasRightName &&
string.Compare(Index, this.rightName,
true) == 0)
75 lock (this.properties)
77 if (!this.properties.TryGetValue(Index, out Rec))
79 Rec = this.GetRecLocked(Index);
80 this.properties[Index] = Rec;
84 if (!(Rec.Property is
null))
86 if (Rec.NrIndexParameters == 1)
91 else if (!(Rec.Field is
null))
98 private PropertyRecord GetRecLocked(
string Index)
103 if (!(this.leftType is
null))
105 PI = this.leftType.GetRuntimeProperty(Index);
108 if (PI.CanRead && PI.GetMethod.IsPublic)
109 return new PropertyRecord(PI,
true);
111 return new PropertyRecord();
114 FI = this.leftType.GetRuntimeField(Index);
118 return new PropertyRecord(FI,
true);
120 return new PropertyRecord();
124 out ParameterInfo[] IndexArguments))
126 return new PropertyRecord(PI,
true, IndexArguments);
130 if (!(this.rightType is
null))
132 PI = this.rightType.GetRuntimeProperty(Index);
135 if (PI.CanRead && PI.GetMethod.IsPublic)
136 return new PropertyRecord(PI,
false);
138 return new PropertyRecord();
141 FI = this.rightType.GetRuntimeField(Index);
145 return new PropertyRecord(FI,
false);
147 return new PropertyRecord();
151 out ParameterInfo[] IndexArguments))
153 return new PropertyRecord(PI,
false, IndexArguments);
157 return new PropertyRecord();
160 private class PropertyRecord
162 public PropertyInfo Property;
163 public ParameterInfo[] IndexArguments;
164 public FieldInfo Field;
166 public int NrIndexParameters;
167 public bool IsStringIndex;
169 public PropertyRecord()
171 this.Property =
null;
174 this.IndexArguments =
null;
175 this.IsStringIndex =
false;
176 this.NrIndexParameters = 0;
179 public PropertyRecord(PropertyInfo Property,
bool Left)
181 this.Property = Property;
184 this.IndexArguments =
null;
185 this.IsStringIndex =
false;
186 this.NrIndexParameters = 0;
189 public PropertyRecord(FieldInfo Field,
bool Left)
191 this.Property =
null;
194 this.IndexArguments =
null;
195 this.IsStringIndex =
false;
196 this.NrIndexParameters = 0;
199 public PropertyRecord(PropertyInfo Property,
bool Left, ParameterInfo[] IndexArguments)
201 this.Property = Property;
204 this.IndexArguments = IndexArguments;
206 if (IndexArguments is
null)
208 this.NrIndexParameters = 0;
209 this.IsStringIndex =
false;
213 this.NrIndexParameters = this.IndexArguments.Length;
214 this.IsStringIndex = this.NrIndexParameters == 1 &&
215 this.IndexArguments[0].ParameterType == typeof(
string);
219 public PropertyRecord(FieldInfo Field,
bool Left, ParameterInfo[] IndexArguments)
221 this.Property =
null;
224 this.IndexArguments = IndexArguments;
226 if (IndexArguments is
null)
228 this.NrIndexParameters = 0;
229 this.IsStringIndex =
false;
233 this.NrIndexParameters = this.IndexArguments.Length;
234 this.IsStringIndex = this.NrIndexParameters == 1 &&
235 this.IndexArguments[0].ParameterType == typeof(
string);
239 public object[] GetIndexArguments(
string Name)
241 if (this.IsStringIndex)
242 return new object[] { Name };
246 return new object[] { Converted };
257 if (this.objectId is
null)
259 StringBuilder sb =
new StringBuilder();
262 if (!(this.left is
null))
266 sb.Append(Id.ToString());
271 if (!(this.right is
null))
275 sb.Append(Id.ToString());
278 this.objectId = sb.ToString();
281 return this.objectId;
Static interface for database persistence. In order to work, a database provider has to be assigned t...
static Task< object > TryGetObjectId(object Object)
Tries to get the Object ID of an object, if it exists.
Generic object. Contains a sequence of properties.
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 nodes in a parsed script tree.
static object UnnestPossibleTaskSync(object Result)
Checks if Result is an asynchronous results. If so, blocks the current thread until the result is co...
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.
Represents a joined object.
string ObjectId
Joined Object ID
JoinedObject(object Left, string LeftName, object Right, string RightName)
Represents a joined object.
override int GetHashCode()
override bool Equals(object obj)