Exemplo n.º 1
0
        private void attributeMap(IMapperConfigurationExpression cfg, Assembly[] asms)
        {
            var autoMapType = typeof(AutoMapAttribute);

            asms.ForEach(asm =>
            {
                var types   = asm.GetTypes().Where(t => t.IsDefined(autoMapType, false));
                var asmName = asm.FullName;
                types.ForEach(t =>
                {
                    cfg.CreateProfile(asmName + "." + t.Name.TrimEnd("Dto") + "Mapper", expression =>
                    {
                        var attr = (AutoMapAttribute[])t.GetCustomAttributes(autoMapType, false);
                        if (attr.Length > 0)
                        {
                            expression.CreateMap(t, attr[0].TargetType);
                            expression.CreateMap(attr[0].TargetType, t);
                        }
                    });
                });
            });
        }