public override ITypeMapper <TChild, TNChild> Clone <TChild, TNChild>() { var mapperClone = new DestinationTypeMapper <TChild, TNChild>(MappingService, MappingServiceProvider); Restore(mapperClone); return(mapperClone); }
public IMemberConfiguration <T, TN> Register <T, TN>() { lock (_lock) { var src = typeof(T); var dest = typeof(TN); var cacheKey = CalculateCacheKey(src, dest); if (SourceService.TypeMappers.ContainsKey(cacheKey) && DestinationService.TypeMappers.ContainsKey(cacheKey)) { throw new InvalidOperationException(string.Format("Mapping from {0} to {1} is already registered", src.FullName, dest.FullName)); } if (src.GetInterfaces().Any(t => t.Name.Contains(typeof(IEnumerable).Name)) && dest.GetInterfaces().Any(t => t.Name.Contains(typeof(IEnumerable).Name))) { throw new InvalidOperationException(string.Format("It is invalid to register mapping for collection types from {0} to {1}, please use just class registration mapping and your collections will be implicitly processed. In case you want to include some custom collection mapping please use: Mapper.RegisterCustom.", src.FullName, dest.FullName)); } var sourceClassMapper = new SourceTypeMapper <T, TN>(SourceService, this); var destinationClassMapper = new DestinationTypeMapper <T, TN>(DestinationService, this); SourceService.TypeMappers[cacheKey] = sourceClassMapper; DestinationService.TypeMappers[cacheKey] = destinationClassMapper; return (new MemberConfiguration <T, TN>(new ITypeMapper <T, TN>[] { sourceClassMapper, destinationClassMapper })); } }
public IMemberConfiguration <T, TN> Register <T, TN>() { lock (_lock) { var src = typeof(T); var dest = typeof(TN); var cacheKey = CalculateCacheKey(src, dest); if (SourceService.TypeMappers.ContainsKey(cacheKey) && DestinationService.TypeMappers.ContainsKey(cacheKey)) { throw new InvalidOperationException(string.Format("Mapping from {0} to {1} is already registered", src.FullName, dest.FullName)); } var sourceClassMapper = new SourceTypeMapper <T, TN>(SourceService); var destinationClassMapper = new DestinationTypeMapper <T, TN>(DestinationService); SourceService.TypeMappers[cacheKey] = sourceClassMapper; DestinationService.TypeMappers[cacheKey] = destinationClassMapper; return (new MemberConfiguration <T, TN>(new ITypeMapper <T, TN>[] { sourceClassMapper, destinationClassMapper })); } }
private IMemberConfiguration <T, TN> RegisterInternal <T, TN>(bool memberCaseInsensitive = true) { lock (_lock) { var src = typeof(T); var dest = typeof(TN); var cacheKey = CalculateCacheKey(src, dest); if (SourceService.TypeMappers.ContainsKey(cacheKey) && DestinationService.TypeMappers.ContainsKey(cacheKey)) { var typeMapper = SourceService.TypeMappers[cacheKey] as ITypeMapper <T, TN>; return(typeMapper?.MemberConfiguration); } if (src.GetInfo().GetInterfaces().Any(t => t.Name.Contains(typeof(IEnumerable).Name)) && dest.GetInfo().GetInterfaces().Any(t => t.Name.Contains(typeof(IEnumerable).Name))) { throw new InvalidOperationException( $"It is invalid to register mapping for collection types from {src.FullName} to {dest.FullName}, please use just class registration mapping and your collections will be implicitly processed. In case you want to include some custom collection mapping please use: Mapper.RegisterCustom."); } var sourceClassMapper = new SourceTypeMapper <T, TN>(SourceService, this); var destinationClassMapper = new DestinationTypeMapper <T, TN>(DestinationService, this); SourceService.TypeMappers[cacheKey] = sourceClassMapper; DestinationService.TypeMappers[cacheKey] = destinationClassMapper; var memberConfiguration = new MemberConfiguration <T, TN>( new ITypeMapper <T, TN>[] { sourceClassMapper, destinationClassMapper }, this); sourceClassMapper.MemberConfiguration = memberConfiguration; destinationClassMapper.MemberConfiguration = memberConfiguration; if (!CustomMappingsBySource.ContainsKey(src.GetHashCode())) { CustomMappingsBySource[src.GetHashCode()] = new List <long>(); } if (!CustomMappingsBySource[src.GetHashCode()].Contains(cacheKey)) { CustomMappingsBySource[src.GetHashCode()].Add(cacheKey); } return(memberConfiguration); } }