While trying to translate between my ViewModel and my domain model using AutoMapper I noticed that it does not play well with Enums marked the the Flags attribute.
Here is a quick mockup of the classes:
ViewModel:
public class TestViewModel
{
// array of individual Enum values
public TestEnum[] TestEnum { get; set; }
}
Domain Model:
public class TestModel
{
// single Enum marked with flags attribute
public TestEnum TestEnum { get; set; }
}
Enum:
[Flags]
public enum TestEnum
{
Test1,
Test2,
Test3,
Test4
}
This is what I am trying to do. I guess I need a Custom resolver of some sort in my Automapper config because it throws an exception when I do Mapper.Map().
My question: How would I accomplish this?
Bonus question: Is this best practice for handling Flags Enums / Bitmasks in Viewmodel -> Domain models (in a MVVM respect)? If not, what practice would you suggest (using AutoMapper or otherwise)?