Skip to content

Commit

Permalink
Merge branch 'ExtensionMethodNull' of https://github.com/lbargaoanu/A…
Browse files Browse the repository at this point in the history
…utoMapper into ExtensionMethodNull
  • Loading branch information
lbargaoanu committed Aug 21, 2017
2 parents a6e1427 + 09877eb commit 0ffe31c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/AutoMapper/Internal/ExpressionFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,11 @@ public static Expression NullCheck(Expression expression, Type destinationType)
if(target is MemberExpression member)
{
target = member.Expression;
if(!member.Member.IsStatic())
{
NullCheck();
}
NullCheck();
}
else if(target is MethodCallExpression method)
{
target = method.Method.IsStatic() ? method.Arguments[0] : method.Object;
target = method.Method.IsStatic() ? method.Arguments.FirstOrDefault() : method.Object;
NullCheck();
}
else if(target?.NodeType == ExpressionType.Parameter)
Expand All @@ -143,7 +140,7 @@ public static Expression NullCheck(Expression expression, Type destinationType)
while(true);
void NullCheck()
{
if(target.Type.IsValueType())
if(target == null || target.Type.IsValueType())
{
return;
}
Expand Down Expand Up @@ -238,4 +235,4 @@ public override Expression Visit(Expression node)
protected override Expression VisitLambda<T>(Expression<T> node) => Lambda(Visit(node.Body), node.Parameters);
}
}
}
}
3 changes: 2 additions & 1 deletion src/UnitTests/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ public class Bar
public class FooDto
{
public string BarSimpleName { get; set; }
public Guid Value { get; set; }
}

protected override MapperConfiguration Configuration => new MapperConfiguration(cfg =>
{
cfg.IncludeSourceExtensionMethods(typeof(BarExtensions));
cfg.CreateMap<Foo, FooDto>();
cfg.CreateMap<Foo, FooDto>().ForMember(d=>d.Value, o=>o.MapFrom(s=>Guid.NewGuid()));
});

[Fact]
Expand Down

0 comments on commit 0ffe31c

Please sign in to comment.