You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's an exception produced when mapping to a class with a ctor:
publicclassDestination{publicDestination(intnumber){Id=number;}publicintId{get;}}publicclassSource{publicintNumber{get;set;}}[Fact]publicvoid Should_Map(){
var config =new TypeAdapterConfig();
config.ForType<Source,Destination>().Map(dest => dest.Id,source => source.Number);
config.Compile();// throws an exception}
The following exception is produced:
System.InvalidOperationException : No default constructor for type 'Destination', please use 'ConstructUsing' or 'MapWith'.
The exception message seems misleading as (I may have missed it in documentation) mapster seems to depend on argument names.
Renaming Destination ctor argument from number to id is enough for the test to succeed. That is, changing to the following:
What should happen in this scenario if name-dependency was reduced?
public class Destination
{
public Destination(int number1, int number2)
{
Id1 = number2;
Id2 = number1;
}
public int Id1 { get; }
public int Id2 { get; }
}
There's an exception produced when mapping to a class with a ctor:
The following exception is produced:
The exception message seems misleading as (I may have missed it in documentation) mapster seems to depend on argument names.
Renaming
Destination
ctor argument fromnumber
toid
is enough for the test to succeed. That is, changing to the following:Suggestions:
The text was updated successfully, but these errors were encountered: