BasicObjectMapper - Aghyad-Khlefawi/Coddee GitHub Wiki
A simple ObjectMapper implementation. This implementation is slower that the ILObjectsMapper but this one can be using in Portable libraries (Xamarin,WUP,WindowsPhone,etc..)
The current implementation only supports one level of mapping but it's very fast for simple POCO objects mapping
C# Example:
public class Person : IUniqueObject<int>
{
public int ID { get; set; }
public string FirstName { get; set; }
public int GetKey
{
get { return ID; }
}
}
public class PersonDbModel : IUniqueObject<int>
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public int GetKey
{
get { return ID; }
}
}
public void map()
{
IObjectMapper mapper = new BasicObjectMapper();
PersonDbModel sourceItem = new PersonDbModel {ID = 1, FirstName = "Aghyad"};
//Auto registration
mapper.RegisterMap<PersonDbModel, Person>();
//result will have the same values as sourceItem
Person result = mapper.Map<Person>(sourceItem);
//Manual registration
mapper.RegisterMap<PersonDbModel, Person>((source, target) =>
{
target.ID = source.ID;
target.FirstName = source.FirstName;
});
//result2 will have the same values as sourceItem
Person result2 = mapper.Map<Person>(sourceItem);
}