I’ve recently just started using Mapster and I’m trying to do a mapping enum values to an object. I tried the simple way to map using .Map() but it doesn’t work. Here’s are the objects
class DropdownDto<T>
{
public T Id {get; set;}
public string StringValue {get; set;}
}
enum WasteClassificationEnum
{
[Display(Name = "Biodegradable Waste Material")
Biodegradable = 1,
[Display(Name = "Recyclables")
Recyclable = 2,
[Display(Name = "Residual Waste Material")
Residual = 3,
[Display(Name = "Uncategorized")
Special = 4
}
class WasteMaterialDto
{
public int Id {get; set;}
public string Name {get; set:}
// ... some more attributes here
}
I wanted to map WasteMaterialDto’s Id and Name to the WasteClassificationEnum then pass it to the DropdownDto.
I tried doing something like this:
TypeAdapterConfig(WasteMaterialDto, DropdownDto<WasteClassificationEnum>>.NewConfig()
.Map(dest => dest.Id, src => src.Id)
.Map(dest => dest.StringValue, src => src.Name);
But this produces a null value. Is this possible? Mapster is a whole new concept for me and I can only find the simplest of samples on the internet.