ObjectMapper is another, but yet useful mapper for object-to-object.
Use the annotations, to indicate what properties shall be mapped:
public class HelloWorld
{
[PropertyMap]
public string Hello { get; set; }
[PropertyMap]
public string World { get; set; }
}
To do the mapping, use the Mapper class (or the IMapper interface in a dependency injection scenario):
var mapper = new Mapper();
var helloWorld = new HelloWorld();
mapper.CreateMapper<DestinyType>()
.Map(helloWorld);
You can use annotations to define target property:
public class HelloWorld
{
[PropertyMap("MyHelloProp")]
public string Hello { get; set; }
[PropertyMap("MyWorldProp")]
public string World { get; set; }
}
And you can set custom values for the target object using lambda:
var mapper = new Mapper();
var helloWorld = new HelloWorld();
mapper.CreateMapper<DestinyType>()
.CustomMap(x => x.CustomProperty, DateTime.Now)
.Map(helloWorld);
You can install ObjectMapper from PM console:
PM> Install-Package ObjectMapper.Framework
ObjectMapper is Copyright © 2017 Filipe da Cunha Vasconcellos and other contributors under the MIT license.