diff --git a/Directory.Build.props b/Directory.Build.props
index 91bec01..6af1dd8 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -2,7 +2,7 @@
Jimmy Bogard
latest
- 3.1.0
+ 3.1.1-preview01
true
$(NoWarn);1701;1702;1591
diff --git a/src/AutoMapper.Extensions.ExpressionMapping/Extensions/VisitorExtensions.cs b/src/AutoMapper.Extensions.ExpressionMapping/Extensions/VisitorExtensions.cs
index be87cc7..a65e672 100644
--- a/src/AutoMapper.Extensions.ExpressionMapping/Extensions/VisitorExtensions.cs
+++ b/src/AutoMapper.Extensions.ExpressionMapping/Extensions/VisitorExtensions.cs
@@ -111,9 +111,9 @@ public static ParameterExpression GetParameterExpression(this Expression express
case ExpressionType.Parameter:
return (ParameterExpression)expression;
case ExpressionType.Quote:
- return GetParameterExpression(GetMemberExpression((LambdaExpression)((UnaryExpression)expression).Operand));
+ return GetParameterExpression(((UnaryExpression)expression).Operand);
case ExpressionType.Lambda:
- return GetParameterExpression(GetMemberExpression((LambdaExpression)expression));
+ return GetParameterExpression(((LambdaExpression)expression).Body);
case ExpressionType.ConvertChecked:
case ExpressionType.Convert:
var ue = expression as UnaryExpression;
diff --git a/src/AutoMapper.Extensions.ExpressionMapping/XpressionMapperVisitor.cs b/src/AutoMapper.Extensions.ExpressionMapping/XpressionMapperVisitor.cs
index b02a7c8..bc20714 100644
--- a/src/AutoMapper.Extensions.ExpressionMapping/XpressionMapperVisitor.cs
+++ b/src/AutoMapper.Extensions.ExpressionMapping/XpressionMapperVisitor.cs
@@ -129,6 +129,14 @@ protected override Expression VisitLambda(Expression node)
return mapped;
}
+ protected override Expression VisitNew(NewExpression node)
+ {
+ if (this.TypeMappings.TryGetValue(node.Type, out Type newType))
+ return Expression.New(newType);
+
+ return base.VisitNew(node);
+ }
+
protected override Expression VisitMemberInit(MemberInitExpression node)
{
if (this.TypeMappings.TryGetValue(node.Type, out Type newType))
diff --git a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/XpressionMapperTests.cs b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/XpressionMapperTests.cs
index 9409e75..d6272e3 100644
--- a/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/XpressionMapperTests.cs
+++ b/tests/AutoMapper.Extensions.ExpressionMapping.UnitTests/XpressionMapperTests.cs
@@ -429,6 +429,32 @@ public void Map__select_method_projecting_to_model_type()
Assert.True(things.Count == 2);
}
+ [Fact]
+ public void Map_MemberInit()
+ {
+ //Arrange
+ Expression> selection = s => new ThingModel { Car = s.Car };
+
+ //Act
+ Expression> selectionMapped = mapper.MapExpression>>(selection);
+
+ //Assert
+ Assert.NotNull(selectionMapped);
+ }
+
+ [Fact]
+ public void Map_Constructor_NoParams()
+ {
+ //Arrange
+ Expression> selection = s => new ThingModel();
+
+ //Act
+ Expression> selectionMapped = mapper.MapExpression>>(selection);
+
+ //Assert
+ Assert.NotNull(selectionMapped);
+ }
+
[Fact]
public void Map__select_method_where_parent_type_is_grandchild_type()
{