MapsterMapper / Mapster

A fast, fun and stimulating object to object Mapper
MIT License
4.29k stars 327 forks source link

Mapster giving issue with c# record no default contractor for type #576

Closed yyogesh closed 1 year ago

yyogesh commented 1 year ago

Mapster giving issue with c# record no default contractor for type "Class_Name", Please use ConttructUsing or MapWith

public record User(int Id, string FirstName, string LastName);

public record UserResponse(int Id, string FirstName, string LastName);

var user = new User(1, "abc", "xyz");

var userResponse = user.Adapt();

stagep commented 1 year ago

Your code example did not compile. The following change to the last line did compile and mapped as expected.

var userResponse = user.Adapt<UserResponse>();

Possibly that is what your code already has but when you do not mark <UserResponse> as code the <UserResponse> disappears in the comments.