private ITypeMapper CreateTypeMapper(Type type)
        {
            var mapperFactory = new MapperFactoryConfig()
                                .CreateMapByAttribute <TargetObject>()
                                .ToMapperFactory();

            return(mapperFactory.Create(type));
        }
        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);
        }
        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);
        }
        public void CoverageFix()
        {
            // Factory
            Assert.Throws <ArgumentNullException>(() => new MapperFactory(null));

            Assert.Throws <ArgumentNullException>(() => new MapperFactoryConfig().ToMapperFactory().Create(null));

            // Config
            var factory = new MapperFactoryConfig().Configure(config => { config.Add <IService, Service>(); }).ToMapperFactory();

            Assert.NotNull(factory.Components.Get <IService>());

            Assert.Throws <ArgumentNullException>(() => new MapperFactoryConfig().Configure(null));

            Assert.Throws <ArgumentNullException>(() => new MapperFactoryConfig().AddMappingFactory(null));
            Assert.Throws <ArgumentNullException>(() => new MapperFactoryConfig().AddProfile(null));

            // Profile
            new MapperFactoryConfig().AddProfile <MapperProfile>().ToMapperFactory();

            Assert.Throws <ArgumentNullException>(() => new MapperFactoryConfig().AddProfile(new ExceptionProfile()));
        }
        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);
        }
Example #6
0
 public static MapperFactoryConfig DefaultDateTimeKind(this MapperFactoryConfig config, DateTimeKind value)
 {
     return(config.AddParameter(Parameter.DateTimeKind, value));
 }
Example #7
0
 public static MapperFactoryConfig DefaultFalseValue(this MapperFactoryConfig config, byte value)
 {
     return(config.AddParameter(Parameter.FalseValue, value));
 }
Example #8
0
 public static MapperFactoryConfig DefaultTextFiller(this MapperFactoryConfig config, byte value)
 {
     return(config.AddParameter(Parameter.TextFiller, value));
 }
Example #9
0
 public static MapperFactoryConfig DefaultEndian(this MapperFactoryConfig config, Endian value)
 {
     return(config.AddParameter(Parameter.Endian, value));
 }
Example #10
0
 public static MapperFactoryConfig DefaultNumberTextDecimalStyle(this MapperFactoryConfig config, NumberStyles value)
 {
     return(config.AddParameter(Parameter.NumberTextDecimalStyle, value));
 }
 public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, Type type)
 {
     return(config.CreateMapByAttribute(type, null, true));
 }
 public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, IEnumerable <Type> types, bool validation)
 {
     return(CreateMapByAttribute(config, types, null, validation));
 }
Example #13
0
 public static MapperFactory ToMapperFactory(this MapperFactoryConfig config)
 {
     return(new MapperFactory(config));
 }
        //--------------------------------------------------------------------------------
        // Config.Multi
        //--------------------------------------------------------------------------------

        public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, IEnumerable <Type> types)
        {
            return(CreateMapByAttribute(config, types, null, true));
        }
 public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, IEnumerable <Type> types, string profile)
 {
     return(CreateMapByAttribute(config, types, profile, true));
 }
        //--------------------------------------------------------------------------------
        // Config.Single
        //--------------------------------------------------------------------------------

        public static MapperFactoryConfig CreateMapByAttribute <T>(this MapperFactoryConfig config)
        {
            return(config.CreateMapByAttribute(typeof(T), null, true));
        }
 public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, Type type, bool validation)
 {
     return(config.CreateMapByAttribute(type, null, validation));
 }
 public static MapperFactoryConfig CreateMapByAttribute(this MapperFactoryConfig config, Type type, string profile)
 {
     return(config.CreateMapByAttribute(type, profile, true));
 }
Example #19
0
 public static MapperFactoryConfig DefaultDateTimeTextEncoding(this MapperFactoryConfig config, Encoding value)
 {
     return(config.AddParameter(Parameter.DateTimeTextEncoding, value));
 }
 public static MapperFactoryConfig CreateMapByExpression(this MapperFactoryConfig config, Type type, int size, Action <ITypeConfigSyntax <object> > action)
 {
     return(config.CreateMapByExpression(type, null, size, action));
 }
Example #21
0
 public static MapperFactoryConfig DefaultDateTimeTextStyle(this MapperFactoryConfig config, DateTimeStyles value)
 {
     return(config.AddParameter(Parameter.DateTimeTextStyle, value));
 }
Example #22
0
 public static MapperFactoryConfig DefaultDelimiter(this MapperFactoryConfig config, params byte[] value)
 {
     return(config.AddParameter(Parameter.Delimiter, value));
 }
Example #23
0
 public static MapperFactoryConfig DefaultNumberTextProvider(this MapperFactoryConfig config, IFormatProvider value)
 {
     return(config.AddParameter(Parameter.NumberTextProvider, value));
 }
Example #24
0
 public static MapperFactoryConfig DefaultTrim(this MapperFactoryConfig config, bool value)
 {
     return(config.AddParameter(Parameter.Trim, value));
 }
Example #25
0
 public static MapperFactoryConfig DefaultNumberTextPadding(this MapperFactoryConfig config, Padding value)
 {
     return(config.AddParameter(Parameter.NumberTextPadding, value));
 }
 public static MapperFactoryConfig CreateMapByAttribute <T>(this MapperFactoryConfig config, string profile, bool validation)
 {
     return(config.CreateMapByAttribute(typeof(T), profile, validation));
 }