Skip to content

Filipedguy/ObjectMapper

Repository files navigation

Build status NuGet Codacy Badge

ObjectMapper

ObjectMapper is another, but yet useful mapper for object-to-object.

Getting started

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);

Nuget

You can install ObjectMapper from PM console:

PM> Install-Package ObjectMapper.Framework

License

ObjectMapper is Copyright © 2017 Filipe da Cunha Vasconcellos and other contributors under the MIT license.

About

Object to object mapper using annotations

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages