private EntityInfo GetEntityInfo(Type type) { EntityInfo infos; if (!EntityInfos.TryGetValue(type, out infos)) { List <PropertyInfo> singleReferences = type .GetProperties() .Where(p => p.PropertyType.GetInterfaces().Contains(typeof(IDbReference))) .ToList(); List <PropertyInfo> multipleReferences = type .GetProperties() .Where(p => p.PropertyType.GetInterfaces().Contains(typeof(IList))) .Where(p => p.PropertyType.GetGenericArguments()[0].GetInterfaces().Contains(typeof(IDbReference))) .ToList(); infos = new EntityInfo(); infos.EntityType = type; List <SingleReferenceProperty> single = new List <SingleReferenceProperty>(); List <MultipleReferenceProperty> multiple = new List <MultipleReferenceProperty>(); foreach (PropertyInfo s in singleReferences) { SingleReferenceProperty reference = new SingleReferenceProperty() { PropertyAccessor = s, ReferenceType = s.PropertyType.GetGenericArguments()[0], ReferenceCreator = Utils.CreateDefaultConstructor <IDbReference>(s.PropertyType) }; single.Add(reference); } foreach (PropertyInfo s in multipleReferences) { MultipleReferenceProperty reference = new MultipleReferenceProperty() { PropertyAccessor = s, ReferenceType = s.PropertyType.GetGenericArguments()[0].GetGenericArguments()[0], ReferenceCreator = Utils.CreateDefaultConstructor <IDbReference>(s.PropertyType.GetGenericArguments()[0]) }; multiple.Add(reference); } infos.SingleReferenceInjectors = single; infos.MultipleReferenceInjectors = multiple; EntityInfos.Add(type, infos); } return(infos); }
/// <summary> /// Get the <see cref="EntityInfo"/> object from the cache. /// </summary> /// If the <paramref name="type"/> has no <see cref="EntityInfo"/> then it will add the and return the <see cref="EntityInfo"/>. /// <param name="type"></param> /// <returns></returns> public static EntityInfo GetEntityInfo(Type type) { EntityInfo entityInfo = null; if (EntityInfos.TryGetValue(type.GetHashCode(), out entityInfo)) { return(entityInfo); } entityInfo = new EntityInfo(type); EntityInfos.Add(type.GetHashCode(), entityInfo); return(entityInfo); }