コード例 #1
0
        public static MapperFactoryConfig CreateMapByExpression(this MapperFactoryConfig config, Type type, string profile, int size, Action <ITypeConfigSyntax <object> > action)
        {
            if (action is null)
            {
                throw new ArgumentNullException(nameof(action));
            }

            var expression = new TypeConfigExpression <object>(type, profile, size);

            action(expression);
            config.AddMappingFactory(expression);
            return(config);
        }
コード例 #2
0
        public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, Type type, string profile, bool validation)
        {
            if (type is null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var mapAttribute = type.GetCustomAttribute <MapAttribute>();

            if (mapAttribute is null)
            {
                throw new ArgumentException($"No MapAttribute. type=[{type.FullName}]", nameof(type));
            }

            config.AddMappingFactory(new AttributeMappingFactory(type, mapAttribute, profile, validation));

            return(config);
        }
コード例 #3
0
        public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, IEnumerable <Type> types, string profile, bool validation)
        {
            if (types is null)
            {
                throw new ArgumentNullException(nameof(types));
            }

            var targets = types
                          .Where(x => x != null)
                          .Select(x => new
            {
                Type      = x,
                Attribute = x.GetCustomAttribute <MapAttribute>()
            })
                          .Where(x => x.Attribute != null);

            foreach (var pair in targets)
            {
                config.AddMappingFactory(new AttributeMappingFactory(pair.Type, pair.Attribute, profile, validation));
            }

            return(config);
        }