Mapper Automap:
Mapper.CreateMap<ObjectType1, ObjectType2>()
.ForMember(o1 => o1.PropName, mapper => mapper.MapFrom(o2 => o2.Prop2Name));
Mapper.Map(object1, object2);
Implicit operator:
public static implicit operator Object1(Object2 o2)
{
Object1 o1 = new Object2();
//Mapping code here...
return o1;
}
AutoMapper is used whenever there are many data properties for objects, and we need to map them between the object of source class to the object of destination class, Along with the knowledge of data structure and algorithms, a developer is required to have excellent development skills as well.
The Implicit Operator According to MSDN, an implicit keyword is used to declare an implicit user-defined type conversion operator. In other words, this gives the power to your C# class, which can accepts any reasonably convertible data type without type casting.
There's no reason you couldn't use both together, by calling Mapper.Map
from the implicit operator.
Using AutoMapper allows you to rely on automatically generated mapping code, so that you don't have to use ForMember
to map each member individually.
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