Пример #1
0
        static List <IMemberBinder> PrepareMemberBinders(Type type, IDataReader reader, ObjectMemberMapper mapper)
        {
            List <IMemberBinder> memberBinders = new List <IMemberBinder>(reader.FieldCount);

            MemberInfo[]      properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetProperty);
            MemberInfo[]      fields     = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.SetField);
            List <MemberInfo> members    = new List <MemberInfo>(properties.Length + fields.Length);

            members.AddRange(properties);
            members.AddRange(fields);

            TypeDescriptor typeDescriptor = EntityTypeContainer.TryGetDescriptor(type);

            for (int i = 0; i < reader.FieldCount; i++)
            {
                string     name      = reader.GetName(i);
                MemberInfo mapMember = TryGetMapMember(members, name, typeDescriptor);

                if (mapMember == null)
                {
                    continue;
                }

                MRMTuple mMapperTuple = mapper.GetMappingMemberMapper(mapMember);
                if (mMapperTuple == null)
                {
                    continue;
                }

                PrimitiveMemberBinder memberBinder = new PrimitiveMemberBinder(mapMember, mMapperTuple, i);
                memberBinders.Add(memberBinder);
            }

            return(memberBinders);
        }
Пример #2
0
        List <IMemberBinder> CreateMemberBinders(IDbContext dbContext)
        {
            ObjectMemberMapper   mapper        = this.ConstructorDescriptor.GetEntityMemberMapper();
            List <IMemberBinder> memberBinders = new List <IMemberBinder>(this.PrimitiveMembers.Count + this.ComplexMembers.Count + this.CollectionMembers.Count);

            foreach (var kv in this.PrimitiveMembers)
            {
                MRMTuple mrmTuple            = mapper.GetMappingMemberMapper(kv.Key);
                PrimitiveMemberBinder binder = new PrimitiveMemberBinder(kv.Key, mrmTuple, kv.Value);
                memberBinders.Add(binder);
            }

            foreach (var kv in this.ComplexMembers)
            {
                MemberValueSetter   setter         = mapper.GetMemberSetter(kv.Key);
                IObjectActivator    memberActivtor = kv.Value.CreateObjectActivator(dbContext);
                ComplexMemberBinder binder         = new ComplexMemberBinder(setter, memberActivtor);
                memberBinders.Add(binder);
            }

            foreach (var kv in this.CollectionMembers)
            {
                MemberValueSetter      setter         = mapper.GetMemberSetter(kv.Key);
                IObjectActivator       memberActivtor = kv.Value.CreateObjectActivator(dbContext);
                CollectionMemberBinder binder         = new CollectionMemberBinder(setter, memberActivtor);
                memberBinders.Add(binder);
            }

            return(memberBinders);
        }