public TDestination Map <TSource, TDestination>(TSource source) where TDestination : new() { var mappingTypes = new MappingTypes(typeof(TSource), typeof(TDestination)); var mappingFunction = GetOrCreateMappingFunction <TSource, TDestination>(mappingTypes); return(mappingFunction(source)); }
private void AddCongiguration(MappingTypes typesMapping, MappingProperties propertiesMapping) { List <MappingProperties> registeredMappings; if (!_configuratedMappings.TryGetValue(typesMapping, out registeredMappings)) { registeredMappings = new List <MappingProperties>(); _configuratedMappings[typesMapping] = registeredMappings; } registeredMappings.Add(propertiesMapping); }
internal IEnumerable <MappingProperties> GetRegisteredMappings <TSource, TDestination>() { var mappingEntryInfo = new MappingTypes(typeof(TSource), typeof(TDestination)); List <MappingProperties> registeredMappings; if (!_configuratedMappings.TryGetValue(mappingEntryInfo, out registeredMappings)) { registeredMappings = new List <MappingProperties>(); } return(registeredMappings); }
private static List <MappingProperties> GetMappingProperties(MappingTypes mappingTypes) { return(( from sourceProperty in mappingTypes.Source.GetProperties() join destinationProperty in mappingTypes.Destination.GetProperties() on sourceProperty.Name equals destinationProperty.Name let mappingProperties = new MappingProperties(sourceProperty, destinationProperty) where CanMapProperties(mappingProperties) select mappingProperties ).ToList()); }
public MapperConfiguration Register <TSource, TDestination>( Expression <Func <TSource, object> > sourcePropertyAccessor, Expression <Func <TDestination, object> > destinationPropertyAccessor) { MappingProperties addingPropertiesMapping = GetAddingsMapping(sourcePropertyAccessor, destinationPropertyAccessor); var typesMapping = new MappingTypes(typeof(TSource), typeof(TDestination)); if (Mapper.CanMapProperties(addingPropertiesMapping)) { AddCongiguration(typesMapping, addingPropertiesMapping); } return(this); }
private Func <TSource, TDestination> GetOrCreateMappingFunction <TSource, TDestination>(MappingTypes mappingTypes) where TDestination : new() { Delegate cachedFunction; Func <TSource, TDestination> mappingFunction; var hasCachedFunction = _mappedTypesFunctions.TryGetValue(mappingTypes, out cachedFunction); if (hasCachedFunction) { mappingFunction = (Func <TSource, TDestination>)cachedFunction; } else { var mappingProperties = GetMappingProperties(mappingTypes); mappingProperties.AddRange(_configuration.GetRegisteredMappings <TSource, TDestination>()); mappingFunction = CreateMappingFunction <TSource, TDestination>(mappingProperties); _mappedTypesFunctions.Add(mappingTypes, mappingFunction); } return(mappingFunction); }
internal static bool CanAssign(MappingTypes typesMapping) { return(CanAssign(typesMapping.Source, typesMapping.Destination)); }