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);
        }
Exemple #2
0
        public void SetValue(object instance, object value)
        {
            if (null == this._valueSetter)
            {
                if (Monitor.TryEnter(this))
                {
                    try
                    {
                        if (null == this._valueSetter)
                        {
                            this._valueSetter = MemberValueSetterContainer.GetMemberValueSetter(this.Definition.Property);
                        }
                    }
                    finally
                    {
                        Monitor.Exit(this);
                    }
                }
                else
                {
                    this.Definition.Property.SetMemberValue(instance, value);
                    return;
                }
            }

            this._valueSetter(instance, value);
        }
Exemple #3
0
        public void SetValue(object instance, object value)
        {
            if (null == this._valueSetter)
            {
                this._valueSetter = MemberValueSetterContainer.GetMemberValueSetter(this.Definition.Property);
            }

            this._valueSetter(instance, value);
        }
Exemple #4
0
 public MRM2(MemberInfo member, MappingType mappingType)
 {
     this._mappingType = mappingType;
     this._valueSetter = MemberValueSetterContainer.GetMemberValueSetter(member);
 }