Beispiel #1
0
        public override void CreateMap(IMapperConfigurationExpression configuration, Type type)
        {
            if (TargetTypes.IsNullOrEmpty())
            {
                return;
            }

            configuration.CreateAutoAttributeMaps(type, TargetTypes, MemberList.Source);

            foreach (var targetType in TargetTypes)
            {
                configuration.CreateAutoAttributeMaps(targetType, new[] { type }, MemberList.Destination);
            }
        }
Beispiel #2
0
 private static void AbpAutoMap(this IMapperConfigurationExpression configuration, IEnumerable <Type> types)
 {
     foreach (var type in types)
     {
         configuration.CreateAutoAttributeMaps(type);
     }
 }
        private void FindAndAutoMapTypes(IMapperConfigurationExpression configuration)
        {
            var _typeFinder = LocalIocManager.IocContainer.Resolve <ITypeFinder>();
            //var types1 = _typeFinder.GetAllTypes();

            var types = _typeFinder.Find(type =>
            {
                var typeInfo = type.GetTypeInfo();
                return(typeInfo.IsDefined(typeof(AutoMapAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapFromAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapToAttribute)));
            }
                                         );

            //var type2 = new List<Type>();
            //type2.Add(typeof(Model));
            //type2.Add(typeof(DestModel));

            //foreach (var type in type2)
            //{
            //    configuration.CreateAutoAttributeMaps(type);
            //}

            foreach (var type in types)
            {
                configuration.CreateAutoAttributeMaps(type);
            }
        }
Beispiel #4
0
        public override void CreateMap(IMapperConfigurationExpression configuration, Type type)
        {
            if (TargetTypes.IsNullOrEmpty())
            {
                return;
            }

            configuration.CreateAutoAttributeMaps(type, TargetTypes, MemberList);
        }
Beispiel #5
0
        /// <summary>创建映射
        /// </summary>
        public override void CreateMap(IMapperConfigurationExpression configuration, Type type)
        {
            if (TargetTypes.IsNullOrEmpty())
            {
                return;
            }

            foreach (var targetType in TargetTypes)
            {
                //configuration.CreateMap(targetType, type, MemberList);
                configuration.CreateAutoAttributeMaps(targetType, new[] { type }, MemberList);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 创建映射
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="type">打标签的类</param>
        public override void CreateMap(IMapperConfigurationExpression configuration, Type type)
        {
            /*
             *
             * [AutoMap(TypeOf(Person),TypeOf(Chinese))]
             * public class Student{}
             *
             * 这里参数的type就是Student,targetTypes就是 Person,Chinese等
             */
            if (TargetTypes.IsNullOrEmpty())
            {
                return;
            }
            //当前类映射到模板类上,当前类是source
            configuration.CreateAutoAttributeMaps(type, TargetTypes, MemberList.Source);

            //遍历所有的目标类,映射到当前类上,当前类是Destination
            foreach (var targetType in TargetTypes)
            {
                configuration.CreateAutoAttributeMaps(targetType, new[] { type }, MemberList.Destination);
            }
        }
        private void FindAndAutoMapTypes(IMapperConfigurationExpression configuration)
        {
            var types = _typeFinder.Find(type =>
                                         type.GetTypeInfo().IsDefined(typeof(AutoMapAttribute)) ||
                                         type.GetTypeInfo().IsDefined(typeof(AutoMapFromAttribute)) ||
                                         type.GetTypeInfo().IsDefined(typeof(AutoMapToAttribute))
                                         );

            foreach (var type in types)
            {
                configuration.CreateAutoAttributeMaps(type);
            }
        }
        private static void FindAndAutoMapTypes(IMapperConfigurationExpression configuration)
        {
            var types = TypeHelper.Find(type =>
            {
                var typeInfo = type.GetTypeInfo();
                return(typeInfo.IsDefined(typeof(AutoMapAttribute)));
            }
                                        );

            foreach (var type in types)
            {
                configuration.CreateAutoAttributeMaps(type);
            }
        }
Beispiel #9
0
        private void FindAndAutoMapTypes(IMapperConfigurationExpression configuration, List <Assembly> assemblies)
        {
            var types = assemblies.SelectMany(t => t.GetTypes()).Where(t =>
            {
                var typeInfo = t.GetTypeInfo();
                return(typeInfo.IsDefined(typeof(AutoMapAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapFromAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapToAttribute)));
            });

            foreach (var type in types)
            {
                configuration.CreateAutoAttributeMaps(type);
            }
        }
        private void FindAndAutoMapTypes(IMapperConfigurationExpression configuration)
        {
            var types = _typeFinder.Find(type =>
                                         type.IsDefined(typeof(AutoMapAttribute)) ||
                                         type.IsDefined(typeof(AutoMapFromAttribute)) ||
                                         type.IsDefined(typeof(AutoMapToAttribute))
                                         );

            Logger.DebugFormat("Found {0} classes define auto mapping attributes", types.Length);

            foreach (var type in types)
            {
                Logger.Debug(type.FullName);
                configuration.CreateAutoAttributeMaps(type);
            }
        }
Beispiel #11
0
        private static void FindAndAutoMapTypes(IMapperConfigurationExpression configuration)
        {
            var types = IocManager.ServiceProvider.GetService <ITypeFinder>()
                        .Find(type =>
            {
                var typeInfo = type.GetTypeInfo();
                return(typeInfo.IsDefined(typeof(AutoMapAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapFromAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapToAttribute)));
            }
                              );

            foreach (var type in types)
            {
                configuration.CreateAutoAttributeMaps(type);
            }
        }
Beispiel #12
0
        private void FindAndAutoMapTypes(IMapperConfigurationExpression configuration)
        {
            var types = _typeFinder.Find(type =>
            {
                var typeInfo = type.GetTypeInfo();
                return(typeInfo.IsDefined(typeof(AutoMapAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapFromAttribute)) ||
                       typeInfo.IsDefined(typeof(AutoMapToAttribute)));
            }
                                         );

            Logger.Debug($"Found {types.Length} classes define auto mapping attributes");

            foreach (var type in types)
            {
                Logger.Debug(type.FullName);
                configuration.CreateAutoAttributeMaps(type);
            }
        }
        /// <summary>找到自动映射的类型,并且生成Mapper
        /// </summary>
        private static void FindAndAutoMapTypes(List <Assembly> assemblies, IMapperConfigurationExpression configurationExpression)
        {
            //全部类型
            var allTypes = new List <Type>();

            foreach (var assembly in assemblies)
            {
                //获取程序集中自动映射的类型
                var autoAttributeTypies = assembly.GetTypes().Where(x =>
                {
                    var typeInfo = x.GetTypeInfo();
                    return(typeInfo.IsDefined(typeof(AutoMapAttribute)) || typeInfo.IsDefined(typeof(AutoMapFromAttribute)) || typeInfo.IsDefined(typeof(AutoMapToAttribute)));
                });
                allTypes.AddRange(autoAttributeTypies);
            }
            //遍历,并且把每个映射都添加进去
            foreach (var type in allTypes)
            {
                configurationExpression.CreateAutoAttributeMaps(type);
            }
        }