private TypeMap GetTypeMap(Type sourceType, Type destinationType) { var map = userDefinedConfiguration.FindTypeMapConfiguration(sourceType, destinationType); if (map == null) { throw new KeyNotFoundException(Tuple.Create(sourceType, destinationType).ToString()); } return(CreateOrGetTypeMap(map)); }
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)); }