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.7-pre02</Version>
<Version>10.0.7-pre03</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
17 changes: 1 addition & 16 deletions src/Mapster.Tests/WhenMappingRecordRegression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,7 @@ public void FixCtorParamMapping()
result.Order.Payment.CVV.ShouldBe("234");
resultID.UserID.ShouldBe("256");
}

[TestMethod]
public void RequiredProperty()
{
var source = new Person553 { FirstMidName = "John", LastName = "Dow" };
var destination = new Person554 { ID = 245, FirstMidName = "Mary", LastName = "Dow" };

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

var result = source.Adapt(destination);

result.ID.ShouldBe(245);
result.FirstMidName.ShouldBe(source.FirstMidName);
result.LastName.ShouldBe(source.LastName);
}


/// <summary>
/// https://github.com/MapsterMapper/Mapster/issues/842
/// </summary>
Expand Down
68 changes: 68 additions & 0 deletions src/Mapster.Tests/WhenMappingRequiredPropertyRegression.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Shouldly;
using System;
using System.Collections.Generic;
using System.Text;

namespace Mapster.Tests
{
[TestClass]
public class WhenMappingRequiredPropertyRegression
{
[TestMethod]
public void RequiredProperty()
{
var source = new Person553 { FirstMidName = "John", LastName = "Dow" };
var destination = new Person554 { ID = 245, FirstMidName = "Mary", LastName = "Dow" };

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

var result = source.Adapt(destination);

result.ID.ShouldBe(245);
result.FirstMidName.ShouldBe(source.FirstMidName);
result.LastName.ShouldBe(source.LastName);
}

[TestMethod]
public void PolymorphicMappingToAbstractClassCompileWithoutError()
{
var config = TypeAdapterConfig.GlobalSettings;

config.NewConfig<ConcreteSource, ConcreteDestination>();

config.NewConfig<AbstractSource, AbstractDestination>()
.Include<ConcreteSource, ConcreteDestination>();

Should.NotThrow(() =>
{
config.Compile();
});

}
}

#region TestClasses

public abstract class AbstractSource
{
public abstract string Name { get; }
}

public class ConcreteSource : AbstractSource
{
public override string Name => "Test";
}

public abstract class AbstractDestination
{
public required string Name { get; set; }
}

public class ConcreteDestination : AbstractDestination
{

}

#endregion TestClasses
}
2 changes: 1 addition & 1 deletion src/Mapster/Adapters/BaseAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected Expression CreateBlockExpressionBody(Expression source, Expression? de
.Where(x => x.GetCustomAttributes()
.Any(y => y.GetType().FullName == "System.Runtime.CompilerServices.RequiredMemberAttribute"));

if (requiremembers.Count() != 0)
if (requiremembers.Count() != 0 && !arg.DestinationType.IsAbstract)
set = CreateInlineExpression(source, arg.CloneWith(MapType.ApplyNullPropagation), true);
else
set = CreateInstantiationExpression(transformedSource, destination, arg);
Expand Down
Loading