public IObjectActivator CreateObjectActivator(IDbContext dbContext) { InstanceCreator instanceCreator = this.ConstructorDescriptor.GetInstanceCreator(); List <IObjectActivator> argumentActivators = this.CreateArgumentActivators(dbContext); List <IMemberBinder> memberBinders = this.CreateMemberBinders(dbContext); IObjectActivator objectActivator; if (dbContext != null) { objectActivator = new ObjectActivatorWithTracking(instanceCreator, argumentActivators, memberBinders, this.CheckNullOrdinal, dbContext); } else { objectActivator = new ComplexObjectActivator(instanceCreator, argumentActivators, memberBinders, this.CheckNullOrdinal); } if (this.IsRoot && this.HasMany()) { TypeDescriptor entityTypeDescriptor = EntityTypeContainer.GetDescriptor(this.ObjectType); List <Tuple <PropertyDescriptor, int> > keys = new List <Tuple <PropertyDescriptor, int> >(entityTypeDescriptor.PrimaryKeys.Count); foreach (PrimitivePropertyDescriptor primaryKey in entityTypeDescriptor.PrimaryKeys) { keys.Add(new Tuple <PropertyDescriptor, int>(primaryKey, this.PrimitiveMembers[primaryKey.Definition.Property])); } IEntityRowComparer entityRowComparer = new EntityRowComparer(keys); objectActivator = new RootEntityActivator(objectActivator, this.CreateFitter(dbContext), entityRowComparer); } return(objectActivator); }
public CacheInfo(ComplexObjectActivator activator, IDataReader reader) { int fieldCount = reader.FieldCount; var readerFields = new ReaderFieldInfo[fieldCount]; for (int i = 0; i < fieldCount; i++) { readerFields[i] = new ReaderFieldInfo(reader.GetName(i), reader.GetFieldType(i)); } this._readerFields = readerFields; this._objectActivator = activator; }
static IObjectActivator GetObjectActivator(Type type, IDataReader reader) { if (type == PublicConstants.TypeOfObject || type == typeof(DapperRow)) { return(new DapperRowObjectActivator()); } List <CacheInfo> caches; if (!ObjectActivatorCache.TryGetValue(type, out caches)) { if (!Monitor.TryEnter(type)) { return(CreateObjectActivator(type, reader)); } try { caches = ObjectActivatorCache.GetOrAdd(type, new List <CacheInfo>(1)); } finally { Monitor.Exit(type); } } CacheInfo cache = TryGetCacheInfoFromList(caches, reader); if (cache == null) { lock (caches) { cache = TryGetCacheInfoFromList(caches, reader); if (cache == null) { ComplexObjectActivator activator = CreateObjectActivator(type, reader); cache = new CacheInfo(activator, reader); caches.Add(cache); } } } return(cache.ObjectActivator); }
static ComplexObjectActivator CreateObjectActivator(Type type, IDataReader reader) { ConstructorInfo constructor = type.GetConstructor(Type.EmptyTypes); if (constructor == null) { throw new ArgumentException(string.Format("The type of '{0}' does't define a none parameter constructor.", type.FullName)); } ConstructorDescriptor constructorDescriptor = ConstructorDescriptor.GetInstance(constructor); ObjectMemberMapper mapper = constructorDescriptor.GetEntityMemberMapper(); InstanceCreator instanceCreator = constructorDescriptor.GetInstanceCreator(); List <IMemberBinder> memberBinders = PrepareMemberBinders(type, reader, mapper); ComplexObjectActivator objectActivator = new ComplexObjectActivator(instanceCreator, new List <IObjectActivator>(), memberBinders, null); objectActivator.Prepare(reader); return(objectActivator); }