Exemplo n.º 1
0
        void Init()
        {
            Type t       = this.Type;
            var  members = t.GetMembers(BindingFlags.Public | BindingFlags.Instance);
            Dictionary <MemberInfo, MRMTuple> mappingMemberMappers           = new Dictionary <MemberInfo, MRMTuple>();
            Dictionary <MemberInfo, Lazy <MemberValueSetter> > memberSetters = new Dictionary <MemberInfo, Lazy <MemberValueSetter> >();

            foreach (var member in members)
            {
                if (!member.HasPublicSetter())
                {
                    continue;
                }

                //只支持公共属性和字段
                Type memberType = member.GetMemberType();

                memberSetters.Add(member, new Lazy <MemberValueSetter>(() =>
                {
                    MemberValueSetter valueSetter = MemberValueSetterContainer.GetMemberValueSetter(member);
                    return(valueSetter);
                }, LazyThreadSafetyMode.ExecutionAndPublication));

                Infrastructure.MappingType mappingType;
                if (MappingTypeSystem.IsMappingType(memberType, out mappingType))
                {
                    MRMTuple mrmTuple = MRMHelper.CreateMRMTuple(member, mappingType);
                    mappingMemberMappers.Add(member, mrmTuple);
                }
            }

            this._mappingMemberMappers = PublicHelper.Clone(mappingMemberMappers);
            this._memberSetters        = PublicHelper.Clone(memberSetters);
        }
Exemplo n.º 2
0
        public static MRMTuple CreateMRMTuple(MemberInfo member, MappingType mappingType)
        {
            MRMTuple mrmTuple = new MRMTuple();

            mrmTuple.StrongMRM = new Lazy <IMRM>(() =>
            {
                return(new MRM(member));
                //Type type = ClassGenerator.CreateMRMType(member);
                //IMRM strongMrm = (IMRM)type.GetDefaultConstructor().Invoke(null);
                //return strongMrm;
            }, LazyThreadSafetyMode.ExecutionAndPublication);

            if (member.GetMemberType().GetUnderlyingType().IsEnum /* 枚举比较特殊 */)
            {
                mrmTuple.SafeMRM = mrmTuple.StrongMRM;
            }
            else
            {
                mrmTuple.SafeMRM = new Lazy <IMRM>(() =>
                {
                    return(new MRM2(member, mappingType));
                }, LazyThreadSafetyMode.ExecutionAndPublication);
            }

            return(mrmTuple);
        }
Exemplo n.º 3
0
        public MRMTuple GetMappingMemberMapper(MemberInfo memberInfo)
        {
            memberInfo = memberInfo.AsReflectedMemberOf(this.Type);
            MRMTuple mapperTuple = null;

            this._mappingMemberMappers.TryGetValue(memberInfo, out mapperTuple);
            return(mapperTuple);
        }