Mapster
Mapster copied to clipboard
Mapster.Tool enable custom property generation for Dtos
First of all thank you for this great project.
I'm trying to use Mapster.Tools to generate some dtos like below, but I can not figure out how to do it.
public class Parent {
public string ParentProp1 { get; set; }
public Child Child { get; set; }
}
public class Child {
public string Prop1 { get; set; }
public string Prop2 { get; set; }
}
// What I want to achieve is something like this
public class ParentListDto {
public string Prop1 { get; set; }
public string ChildProp1 { get; set; }
public string ChildProp2 { get; set; }
}
// works like a charm
cfg.Map(x => x.ParentProp1, "Prop1");
// This kind of configuration wouldn't work because the second one will override the first one and
// I think actually it's correct this way.
cfg.Map(x => x.Child, typeof(string), "ChildProp1");
cfg.Map(x => x.Child, typeof(string), "ChildProp2");
// But it would be nice if we can do something like this
cfg.CreateProps<string>("ChildProp1", "ChildProp2");
I checked the source code of the Mapster.Tools and if I understand correctly unfortunately this kind of property generation isn't supported yet.
Is there a solution to this that I may not have noticed?
In order to identify issues that are still active, we are closing issues that we believe are either resolved or are dormant. If your issue is still active then please reopen. Thanks.