Skip to content

Commit 5848f85

Browse files
committed
fix: fix bug in MapsterMapper#903. Drop collect ctor param with Getter == null
1 parent 4ceb064 commit 5848f85

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/Mapster/Adapters/BaseClassAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ protected Expression CreateInstantiationExpression(Expression source, ClassMappi
220220
var arguments = new List<Expression>();
221221
foreach (var member in members)
222222
{
223-
arg.Context.NullChecks.UnionWith(members.Select(x=>(x.Getter,arg)));
223+
arg.Context.NullChecks.UnionWith(members.Where(x=>x.Getter != null).Select(x=>(x.Getter,arg)));
224224
var parameterInfo = (ParameterInfo)member.DestinationMember.Info!;
225225
var defaultConst = parameterInfo.IsOptional
226226
? Expression.Constant(parameterInfo.DefaultValue, member.DestinationMember.Type)

src/Mapster/Utils/ExpressionEx.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,11 +436,14 @@ public static Expression ApplyNullPropagation(this Expression getter)
436436

437437
public static Expression ApplyNullPropagationFromCtor(this Expression getter, Expression adapt, CompileArgument arg)
438438
{
439+
if (getter == null)
440+
return adapt;
441+
439442
Expression? condition = null;
440443
var current = getter;
441444
var checks = arg.Context.NullChecks
442445
.Where(x=> !object.ReferenceEquals(x.arg,arg))
443-
.Select(x=>x.param.Type);
446+
.Select(x=>x.param?.Type);
444447

445448
while (current != null)
446449
{

0 commit comments

Comments
 (0)