2using System.Collections.Generic;
3using System.Reflection;
17 private readonly Dictionary<string, Rec> properties =
new Dictionary<string, Rec>();
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.PI is
null))
91 else if (!(Rec.FI is
null))
98 private Rec 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 Rec() { PI = PI, Left =
true };
114 FI = this.leftType.GetRuntimeField(Index);
118 return new Rec() { FI = FI, Left =
true };
124 return new Rec() { PI = PI, Left =
true, Indexed =
true };
127 if (!(this.rightType is
null))
129 PI = this.rightType.GetRuntimeProperty(Index);
132 if (PI.CanRead && PI.GetMethod.IsPublic)
133 return new Rec() { PI = PI };
138 FI = this.rightType.GetRuntimeField(Index);
142 return new Rec() { FI = FI };
148 return new Rec() { PI = PI, Indexed =
true };
156 public PropertyInfo PI;
169 if (this.objectId is
null)
171 StringBuilder sb =
new StringBuilder();
174 if (!(this.left is
null))
178 sb.Append(Id.ToString());
183 if (!(this.right is
null))
187 sb.Append(Id.ToString());
190 this.objectId = sb.ToString();
193 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.
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)