I'm try to learn Mapster. I have classes like this
class In
{
public string A;
public string B;
public string C;
}
class Out
{
public Sub Sub;
public string C;
}
class Sub
{
public string A;
public string B;
public Sub(string a, string b)
=>(A,B) = (a,b);
}
Create a config:
var mapper = new Mapper();
mapper.Config
.ForType<In, Out>()
.Map(@out => @out.C, @in=> @in.C)
.Map(@out=> @out.Sub, @in => new Sub(@in.A, @in.B));
Now, if I try map object - everythink is ok, but if I add second costructor to Sub
class
class Sub
{
public string A;
public string B;
public Sub(string a, string b)
=>(A,B) = (a,b);
public Sub(string a)=> A=a;
}
Mapster throe exception in runtime:
Error while compiling
source=UserQuery+In
destination=UserQuery+Out
type=Map
Error while compiling
source=UserQuery+Sub
destination=UserQuery+Sub
type=Map
No default constructor for type 'Sub', please use 'ConstructUsing' or 'MapWith'
I try read the docs, about ConstructUsing
and MapWith
and this is something not what I need (or am I doing something wrong). How I can do this?