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 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); }