12 [ArchivingTime(nameof(ArchivingTime))]
13 public sealed
class GenericObject : ICollection<KeyValuePair<string, object>>
16 private Dictionary<string, object> propertiesByName =
null;
17 private string collectionName =
null;
18 private string typeName =
null;
19 private int archivingTime = 0;
20 private bool propertiesUpdated =
false;
21 private Guid objectId = Guid.Empty;
65 get => this.collectionName;
66 set => this.collectionName = value;
75 set => this.typeName = value;
84 set => this.objectId = value;
93 get => this.archivingTime;
94 set => this.archivingTime = value;
102 if (this.propertiesUpdated)
103 this.BuildEnumerable();
105 return this.properties.GetEnumerator();
111 IEnumerator IEnumerable.GetEnumerator()
113 if (this.propertiesUpdated)
114 this.BuildEnumerable();
116 return this.properties.GetEnumerator();
122 public Dictionary<string,object>.KeyCollection
Keys
126 if (this.propertiesByName is
null)
127 this.BuildDictionary();
129 return this.propertiesByName.Keys;
136 public Dictionary<string, object>.ValueCollection
Values
140 if (this.propertiesByName is
null)
141 this.BuildDictionary();
143 return this.propertiesByName.Values;
152 public object this[
string PropertyName]
156 if (this.propertiesByName is
null)
157 this.BuildDictionary();
159 if (this.propertiesByName.TryGetValue(PropertyName, out
object Result))
167 if (this.propertiesByName is
null)
168 this.BuildDictionary();
170 this.propertiesByName[PropertyName] = value;
171 this.propertiesUpdated =
true;
183 if (this.propertiesByName is
null)
184 this.BuildDictionary();
186 return this.propertiesByName.TryGetValue(PropertyName, out Value);
196 if (this.propertiesByName is
null)
197 this.BuildDictionary();
199 if (!this.propertiesByName.
Remove(PropertyName))
202 this.propertiesUpdated =
true;
207 private void BuildDictionary()
209 this.propertiesByName = this.properties as Dictionary<string, object>;
210 if (this.propertiesByName is
null)
212 this.propertiesByName =
new Dictionary<string, object>();
214 foreach (KeyValuePair<string, object> P
in this.properties)
215 this.propertiesByName[P.Key] = P.Value;
219 private void BuildEnumerable()
222 Dictionary<string, bool> Added =
new Dictionary<string, bool>();
224 foreach (KeyValuePair<string, object> P
in this.properties)
226 if (!this.propertiesByName.TryGetValue(P.Key, out
object Value))
229 List.
Add(
new KeyValuePair<string, object>(P.Key, Value));
233 foreach (KeyValuePair<string, object> P
in this.propertiesByName)
235 if (Added.ContainsKey(P.Key))
241 this.properties = List;
251 if (this.propertiesUpdated)
252 this.BuildEnumerable();
254 return this.properties;
265 if (this.propertiesByName is
null)
266 this.BuildDictionary();
268 return this.propertiesByName.Count;
286 public void Add(KeyValuePair<string, object> item)
288 this[item.Key] = item.Value;
296 if (this.propertiesByName is
null)
297 this.propertiesByName =
new Dictionary<string, object>();
299 this.propertiesByName.Clear();
301 this.propertiesUpdated =
true;
307 public bool Contains(KeyValuePair<string, object> item)
309 if (this.propertiesByName is
null)
310 this.BuildDictionary();
312 if (!this.propertiesByName.TryGetValue(item.Key, out
object Value))
316 return item.Value is
null;
318 return Value.Equals(item.Value);
324 public void CopyTo(KeyValuePair<string, object>[] array,
int arrayIndex)
326 foreach (KeyValuePair<string, object> P
in this)
327 array[arrayIndex++] = P;
333 public bool Remove(KeyValuePair<string, object> item)
335 if (this.propertiesByName is
null)
336 this.BuildDictionary();
338 if (!this.propertiesByName.TryGetValue(item.Key, out
object Value))
343 if (!(item.Value is
null))
346 else if (!Value.Equals(item.Value))
349 this.propertiesByName.Remove(item.Key);
350 this.propertiesUpdated =
true;
359 this.collectionName != GenObj.collectionName ||
360 this.typeName != GenObj.typeName ||
361 this.objectId != GenObj.objectId)
366 if (this.propertiesByName is
null)
367 this.BuildDictionary();
369 if (GenObj.propertiesByName is
null)
370 GenObj.BuildDictionary();
372 if (this.propertiesByName.Count != GenObj.propertiesByName.Count)
375 foreach (KeyValuePair<string, object> P
in this.propertiesByName)
377 if (!GenObj.propertiesByName.TryGetValue(P.Key, out
object Value))
380 if (!PropertyEquals(Value, P.Value))
387 private static bool PropertyEquals(
object Value1,
object Value2)
389 if (Value1 is
null ^ Value2 is
null)
392 if (Value1 is
null || Value1.Equals(Value2))
395 if (Value1 is Array A && Value2 is Array B)
402 for (i = 0; i < c; i++)
404 if (!PropertyEquals(A.GetValue(i), B.GetValue(i)))
417 if (this.propertiesByName is
null)
418 this.BuildDictionary();
420 int Result = this.objectId.GetHashCode();
421 Result ^= Result << 5 ^ this.typeName.GetHashCode();
422 Result ^= Result << 5 ^ this.collectionName.GetHashCode();
424 foreach (KeyValuePair<string, object> P
in this.propertiesByName)
426 Result ^= Result << 5 ^ P.Key.GetHashCode();
427 Result ^= Result << 5 ^ P.Value.GetHashCode();
440 if (this.propertiesByName is
null)
441 this.BuildDictionary();
443 return this.propertiesByName.ContainsKey(PropertyName);
453 return this[PropertyName];
Generic object. Contains a sequence of properties.
int Count
ICollection<T>.Count
IEnumerable< KeyValuePair< string, object > > Properties
Current set of properties.
bool HasProperty(string PropertyName)
If the object has a property with a given name.
bool Remove(string PropertyName)
Removes a named property.
Dictionary< string, object >.KeyCollection Keys
Gets an enumeration of available key names.
bool TryGetFieldValue(string PropertyName, out object Value)
Gets the value of a field or property of the object, given its name.
string TypeName
Type name.
void Add(KeyValuePair< string, object > item)
ICollection<T>.Add
int ArchivingTime
Archiving time, in days. 0=No archiving. int.MaxValue=No time limit.
bool IsReadOnly
ICollection<T>.IsReadOnly
bool Contains(KeyValuePair< string, object > item)
ICollection<T>.Contains
bool Remove(KeyValuePair< string, object > item)
ICollection<T>.Remove
override int GetHashCode()
IEnumerator< KeyValuePair< string, object > > GetEnumerator()
IEnumerable<T>.GetEnumerator()
string CollectionName
Collection name.
Dictionary< string, object >.ValueCollection Values
Gets an enumeration of available values.
object GetProperty(string PropertyName)
Gets the value of a given property.
override bool Equals(object obj)
void Clear()
ICollection<T>.Clear
void CopyTo(KeyValuePair< string, object >[] array, int arrayIndex)
ICollection<T>.Contains
GenericObject(string CollectionName, string TypeName, Guid ObjectId, params KeyValuePair< string, object >[] Properties)
Generic object. Contains a sequence of properties.
GenericObject(string CollectionName, string TypeName, Guid ObjectId, IEnumerable< KeyValuePair< string, object > > Properties)
Generic object. Contains a sequence of properties.
A chunked list is a linked list of chunks of objects of type T .
bool Remove(T Item)
Removes an element from the collection.
void Add(T Item)
Adds an item to the collection.