I'm a complete noob to Automapper and I'm wondering if its possible to map 2 enum values in the source to 1 in the destination.
In the example below I want to map both VisaCredit and VisaDebit to Visa.
Source:
public enum CardType { VisaCredit, VisaDebit, MasterCard, AmericanExpress, SwitchMaestro }
Destination:
public enum CardType { Visa, MasterCard, AmericanExpress, SwitchMaestro }
You could create a mapping for those types, then define a custom converter:
Mapper.CreateMap<X.CardType, Y.CardType>().ConvertUsing(CardTypeConverter.Convert);
Your card type mapping function would look something similar to this (other mappings omitted for brevity):
public class CardTypeConverter
{
public static Y.CardType Convert(X.CardType cardType)
{
switch(cardType)
{
...
case X.CardType.VisaCredit:
case X.CardType.VisaDebit:
return Y.CardType.Visa;
...
}
}
}
This might not be the most succinct method available for mapping two enum values to one, but it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With