Bottom line, after reviewing comments:
Not possible with Mapster, and it's not Mapster's "mandate" - it belongs to business logic (before/after mapping).
Original question:
Is there a way to exclude/ignore records/entries according to their value?
For instance with:
public class Source
{
public string Name { get; set; }
public string Value { get; set; }
}
public class Destination
{
public string Name { get; set; }
public string Number { get; set; }
}
and mapping:
TypeAdapterConfig<Source, Destination>.NewConfig()
.Map(dest => dest.Name, src => src.Name)
.Map(dest => dest.Number, src => src.Value);
Assuming I have:
var src = new List<Source>[]{
new Source { Name = "one", Value = "1" },
new Source { Name = "two", Value = "2" },
new Source { Name = "three", Value = "3" }
};
And I want only records whose names have 3 letters or less (i.e. include one
and two
but not three
), so output will be:
Destination { Name = "one", Number = "1" },
Destination { Name = "two", Number = "2" },
and Destination { Name = "three", Number = "3" }
is left out.
Is there a way to accomplish it with Mapster?