Exemple #1
0
        public static MRMTuple CreateMRMTuple(MemberInfo member, MappingType mappingType)
        {
            MRMTuple mrmTuple = new MRMTuple();

            mrmTuple.StrongMRM = new Lazy <IMRM>(() =>
            {
                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);
        }
Exemple #2
0
        public static IMRM CreateMRM(MemberInfo member, MappingType mappingType)
        {
            Type type = ClassGenerator.CreateMRMType(member);
            IMRM obj  = (IMRM)type.GetConstructor(Type.EmptyTypes).Invoke(null);

            return(obj);
        }
Exemple #3
0
        public static bool IsMappingType(Type type, out MappingType mappingType)
        {
            Type underlyingType = type.GetUnderlyingType();

            if (underlyingType.IsEnum)
            {
                underlyingType = Enum.GetUnderlyingType(underlyingType);
            }

            return(_mappingTypes.TryGetValue(underlyingType, out mappingType));
        }
Exemple #4
0
        /// <summary>
        /// 配置映射的类型
        /// </summary>
        /// <typeparam name="T">元数据类型</typeparam>
        /// <returns></returns>
        public static MappingTypeBuilder Configure <T>()
        {
            Type        type = typeof(T);
            MappingType mappingType;

            if (!_mappingTypes.TryGetValue(type, out mappingType))
            {
                lock (_lockObj)
                {
                    if (!_mappingTypes.TryGetValue(type, out mappingType))
                    {
                        mappingType         = new MappingType(type);
                        _mappingTypes[type] = mappingType;
                    }
                }
            }

            return(new MappingTypeBuilder(mappingType));
        }
Exemple #5
0
 static void Add(Dictionary <Type, MappingType> dic, MappingType mappingType)
 {
     dic.Add(mappingType.Type, mappingType);
 }
Exemple #6
0
 public MRM2(MemberInfo member, MappingType mappingType)
 {
     this._mappingType = mappingType;
     this._valueSetter = MemberValueSetterContainer.GetMemberValueSetter(member);
 }
Exemple #7
0
 public MappingTypeBuilder(MappingType mappingType)
 {
     this._mappingType = mappingType;
 }