public Expression BuildSource(Expression expression, Type destinationType, IMappingConfiguration mappingConfiguration) { var map = userDefinedConfiguration.FindTypeMapConfiguration(expression.Type, destinationType); if (map == null) { return(null); } if (processed.Add(map) == false || map.HasIncludes() == false) { var typeMap = CreateOrGetTypeMap(map); var lambda = newObjectMapperBuilder.Build(typeMap, mappingConfiguration); return(new ParameterRewriter(lambda.Parameters[0], expression).Visit(lambda.Body)); } var typeMaps = GetTypeMapsWithIncludes(map).ToArray(); var dynamicMapper = DynamicMapperBuilder.BuildDynamicMapperType(typeMaps); var instance = Activator.CreateInstance(dynamicMapper, mappingConfiguration); return(Expression.Convert(Expression.Call(Expression.Constant(instance), "DynamicMap", Type.EmptyTypes, expression), destinationType)); }
public LambdaExpression Build(TypeMap typeMap, IMappingConfiguration configuration) { var tuple = Tuple.Create(typeMap.SourceType, typeMap.DestinationType); return(concurrentDictionary.GetOrAdd(tuple, k => inner.Build(typeMap, configuration))); }
public LambdaExpression BuildExisting(Type sourceType, Type destinationType) { return(existingObjectMapperBuilder.Build(GetTypeMap(sourceType, destinationType), this)); }