Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<!-- Properties related to build/pack -->
<IsPackable>false</IsPackable>
<Version>10.0.5</Version>
<Version>10.0.6</Version>
<MapsterPluginsTFMs>netstandard2.0;net10.0;net9.0;net8.0</MapsterPluginsTFMs>
<MapsterTFMs>netstandard2.0;net10.0;net9.0;net8.0</MapsterTFMs>
<MapsterEFCoreTFMs>net10.0;net9.0;net8.0</MapsterEFCoreTFMs>
Expand Down
1 change: 1 addition & 0 deletions src/Mapster.Core/Enums/MapType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public enum MapType
Map = 1,
MapToTarget = 2,
Projection = 4,
ApplyNullPropagation = 8,
}
}
6 changes: 1 addition & 5 deletions src/Mapster.Tests/WhenMappingRecordRegression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -449,11 +449,7 @@ public void RequiredProperty()
{
var source = new Person553 { FirstMidName = "John", LastName = "Dow" };
var destination = new Person554 { ID = 245, FirstMidName = "Mary", LastName = "Dow" };

TypeAdapterConfig<Person553, Person554>.NewConfig()
//.Map(dest => dest.ID, source => 0)
.Ignore(x => x.ID);


var s = source.BuildAdapter().CreateMapToTargetExpression<Person554>();

var result = source.Adapt(destination);
Expand Down
2 changes: 1 addition & 1 deletion src/Mapster/Adapters/BaseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@
.Any(y => y.GetType().FullName == "System.Runtime.CompilerServices.RequiredMemberAttribute"));

if (requiremembers.Count() != 0)
set = CreateInlineExpression(source, arg, true);
set = CreateInlineExpression(source, arg.CloneWith(MapType.ApplyNullPropagation), true);
else
set = CreateInstantiationExpression(transformedSource, destination, arg);

Expand All @@ -239,7 +239,7 @@

}

if (set.NodeType == ExpressionType.Throw)

Check warning on line 242 in src/Mapster/Adapters/BaseAdapter.cs

View workflow job for this annotation

GitHub Actions / build

Dereference of a possibly null reference.
{
blocks.Add(set);
}
Expand Down
3 changes: 2 additions & 1 deletion src/Mapster/Adapters/BaseClassAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

#region Build the Adapter Model

protected ClassMapping CreateClassConverter(Expression source, ClassModel classModel, CompileArgument arg, Expression? destination = null, bool ctorMapping = false, ClassModel recordRestorMemberModel = null)

Check warning on line 18 in src/Mapster/Adapters/BaseClassAdapter.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
var destinationMembers = classModel.Members;
var unmappedDestinationMembers = new List<string>();
Expand Down Expand Up @@ -113,7 +113,8 @@
Destination = (ParameterExpression?)destination,
UseDestinationValue = IsCanUsingDestinationValue(arg, destinationMember),
};
if(getter == null && !arg.DestinationType.IsRecordType()
if(arg.MapType == MapType.ApplyNullPropagation &&
getter == null && !arg.DestinationType.IsRecordType()
&& destinationMember.Info is PropertyInfo propinfo)
{
if (propinfo.GetCustomAttributes()
Expand Down Expand Up @@ -212,7 +213,7 @@
&& ignore.Condition == null;
}

protected Expression CreateInstantiationExpression(Expression source, ClassMapping classConverter, CompileArgument arg, Expression? destination, ClassModel recordRestorParamModel = null)

Check warning on line 216 in src/Mapster/Adapters/BaseClassAdapter.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
var members = classConverter.Members;

Expand Down
24 changes: 24 additions & 0 deletions src/Mapster/Compile/CompileArgument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,29 @@ select split
_fetchConstructUsing = true;
return _constructUsing;
}

public CompileArgument CloneWith(MapType? mapType = null)
{
var result = new CompileArgument()
{
SourceType = this.SourceType,
DestinationType = this.DestinationType,
MapType = this.MapType,
ExplicitMapping = this.ExplicitMapping,
Settings = this.Settings,
Context = this.Context,
UseDestinationValue = this.UseDestinationValue,
ConstructorMapping = this.ConstructorMapping,
_srcNames = this._srcNames,
_destNames = this._destNames,
_fetchConstructUsing = this._fetchConstructUsing,
_constructUsing = this._constructUsing
};

if (mapType != null)
result.MapType = mapType.Value;

return result;
}
}
}
Loading