public override IEnumerable <T> Query <T>(Func <T, bool> query) { IEnumerable <T> results = ObjectReaderWriter.Query <T>(query); LoadXrefCollectionValues <T>(results); return(results); }
public override IEnumerable <object> Query(Type type, Dictionary <string, object> queryParameters) { List <object> results = new List <object>(); object[] queryResults = ObjectReaderWriter.Query(type, o => { return(WherePropertiesEqual(queryParameters, o)); }); results.AddRange(queryResults); results.Each(o => LoadXrefCollectionValues(o)); return(results); }
public override IEnumerable <T> Query <T>(Dictionary <string, object> queryParameters) { List <T> results = new List <T>(); T[] queryResults = ObjectReaderWriter.Query <T>(o => { return(WherePropertiesEqual(queryParameters, o)); }); results.AddRange(queryResults); LoadXrefCollectionValues <T>(results); return(results); }
public void LoadXrefCollectionValues(object data) { Type type = data.GetType(); Meta meta = data as Meta ?? new Meta(data, ObjectReaderWriter); Type listType = typeof(List <>); string dataHash = meta.Hash; List <Meta> leftMeta = new List <Meta>(); TypeXref[] leftXrefs = TypeSchema.Xrefs.Where(xref => xref.Left.Equals(type)).ToArray(); foreach (TypeXref leftXref in leftXrefs) { Type genericRight = listType.MakeGenericType(leftXref.Right); IList listInstance = genericRight.Construct <IList>(); XrefInfo[] xrefs = ObjectReaderWriter.Query <XrefInfo>(xref => xref.LeftHash.Equals(dataHash)); foreach (XrefInfo xref in xrefs) { object value = ObjectReaderWriter.ReadByHash(Type.GetType(xref.RightType), xref.RightHash); Meta valueMeta = new Meta(value, ObjectReaderWriter); if (!leftMeta.Contains(valueMeta)) { leftMeta.Add(valueMeta); listInstance.Add(value); } } if (leftXref.RightCollectionProperty.PropertyType.IsArray) { Array arr = Array.CreateInstance(leftXref.Right, listInstance.Count); listInstance.CopyTo(arr, 0); leftXref.RightCollectionProperty.SetValue(data, arr); } else { leftXref.RightCollectionProperty.SetValue(data, listInstance); } } List <Meta> rightMeta = new List <Meta>(); TypeXref[] rightXrefs = TypeSchema.Xrefs.Where(xref => xref.Right.Equals(type)).ToArray(); foreach (TypeXref rightXref in rightXrefs) { Type genericLeft = listType.MakeGenericType(rightXref.Left); IList listInstance = genericLeft.Construct <IList>(); XrefInfo[] xrefs = ObjectReaderWriter.Query <XrefInfo>(xref => xref.RightHash.Equals(dataHash)); foreach (XrefInfo xref in xrefs) { object value = ObjectReaderWriter.ReadByHash(Type.GetType(xref.LeftType), xref.LeftHash); Meta valueMeta = new Meta(value, ObjectReaderWriter); if (!rightMeta.Contains(valueMeta)) { rightMeta.Add(valueMeta); listInstance.Add(value); } } if (rightXref.LeftCollectionProperty.PropertyType.IsArray) { Array arr = Array.CreateInstance(rightXref.Left, listInstance.Count); listInstance.CopyTo(arr, 0); rightXref.LeftCollectionProperty.SetValue(data, arr); } else { rightXref.LeftCollectionProperty.SetValue(data, listInstance); } } }
public override IEnumerable <object> Query(Type type, Func <object, bool> predicate) { return(ObjectReaderWriter.Query(type, predicate)); }