Which is the best approach? AutoMapper against implicit (C# Reference)

AutoMapper uses reflection to map properties (slight performance overhead), allows advanced custom rules for mapping and requires 1 line of code in basic (common?) scenarios.

Implicit operators require you to specify each property, are prone to errors (adding a new property but not adding it to the operator), are more difficult to setup for multiple types, create lots of useless code and even in the most basic setup you still have N lines of code where N is the amount of properties.

I think it speaks for itself.


I say no to this use of implicit.

The viewmodel in this example has no extra properties. However if this really was the case you wouldn't require a viewmodel at all. in reality it would have a number of other properties, possibly containing data not from the original model. eg. IsSelected or something.

The implicit conversion is suppose to work without loss of data and this would not be possible with the reverse conversion back to the model

Secondly!

The purpose of the viewmodel is to match data required by the view. you are supposed to have mutiple viewmodels per model. eg. perhaps you have an edit view and a non editable view. or a mobile app and a webpage!

the model shouldn't know about these views or their models and the use of implicit would require it to be coupled

Tags:

C#

Automapper