Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Mapster/Adapters/RecordTypeAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@

protected override bool CanMap(PreCompileArgument arg)
{
return arg.DestinationType.IsRecordType() && arg.MapType != MapType.Projection;
return arg.DestinationType.IsRecordType();
}

protected override bool CanInline(Expression source, Expression? destination, CompileArgument arg)
{
if(arg.MapType == MapType.Projection)
return true;
return false;
}

protected override Expression CreateInlineExpression(Expression source, CompileArgument arg, bool IsRequiredOnly = false)
{
return base.CreateInstantiationExpression(source, arg);
return CreateInstantiationExpression(source, arg);
}
protected override Expression CreateInstantiationExpression(Expression source, Expression? destination, CompileArgument arg)
{
Expand All @@ -51,7 +53,7 @@
}


return RecordInlineExpression(source, destination, arg, installExpr); // Activator field when not include in public ctor

Check warning on line 56 in src/Mapster/Adapters/RecordTypeAdapter.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference return.
}

private Expression? RecordInlineExpression(Expression source, Expression? destination, CompileArgument arg, Expression installExpr)
Expand Down Expand Up @@ -101,7 +103,7 @@
binEx.Right is ConstantExpression { Value: null })
adapt = condEx.IfFalse;
}
var destinationCompareNull = Expression.Equal(destination, Expression.Constant(null, destination.Type));

Check warning on line 106 in src/Mapster/Adapters/RecordTypeAdapter.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
var sourceCondition = Expression.NotEqual(member.Getter, Expression.Constant(null, member.Getter.Type));
var destinationCanbeNull = Expression.Condition(destinationCompareNull, member.DestinationMember.Type.CreateDefault(), member.DestinationMember.GetExpression(destination));
adapt = Expression.Condition(sourceCondition, adapt, destinationCanbeNull);
Expand Down Expand Up @@ -152,7 +154,7 @@
contructorMembers.Any(x => string.Equals(x.Name, member.Name, StringComparison.InvariantCultureIgnoreCase)))
continue;

lines.Add(Expression.Bind((MemberInfo)member.Info, Expression.MakeMemberAccess(destination, (MemberInfo)member.Info)));

Check warning on line 157 in src/Mapster/Adapters/RecordTypeAdapter.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.

Check warning on line 157 in src/Mapster/Adapters/RecordTypeAdapter.cs

View workflow job for this annotation

GitHub Actions / build

Converting null literal or possible null value to non-nullable type.
}

return lines;
Expand Down
Loading