Is there a Value Injection built using Lambda mapping?

May 5, 2011 at 2:23 PM

Suppose I had 2 classes

public class Person {

public string First_Name { get;set; }
public string LastNm { get;set; }
public string MiddleInitial {get; set; }
public string ID {get;set; }
public string Email {get; set }


public class User {

public string FirstName { get;set; }
public string LastName { get;set; }
public string MiddleInitial {get; set; }
public string ID {get;set; }
public string Email {get; set }


Is there something out of box that is able to do something like

public class PersonToUser : LookupValueInjection<Person, User>
    public override CustomMapping(Expression<Person> p, Expression<User> u)
        Map(p => p.First_Name, u => u.FirstName)
        Map(p => p.LastNm, u => u.LastName)

        //mapping is handled normally for ID, Email, MiddleInitial since nothing targets them specifically

May 5, 2011 at 2:48 PM
Edited May 5, 2011 at 2:52 PM

if there would be and you would write




instead of writing this injection could as well just write:


user.FirstName = person.First_Name;

user.LastName = person.LastNme;


valueinjections are not about mapping form one specific type to another specific type, but rather properties,

for example you could do an injection that would ignore underlines when mapping from source to target, so that stuff like this:

a.Foo_Name = b.FooName;

a.A_b_c = y.Ab__c;

would be done automatically

May 5, 2011 at 3:21 PM

The main issue is this accounts for probably 95% of the need I have for mapping. That almost every property is an exact duplicate on both sides of the mapping and there's a couple that are the same value just different names. AutoMapper is a complete pain in the ass that I need to map EVERYTHING explicitly, I only need a couple of explicit mappings and the rest can always be handled by default conventions.

May 5, 2011 at 5:02 PM

well, you could do like this:


a.Foo = b.Bar;


and if you want all your mapping code to be in one place (like automapper) you could do something like this:



T1 Map(T2)


after you could have a generic implementation of this and other one's that inherit it and add stuff, also by having specified T1 and T2 you can do a.Foo = b.Bar

May 6, 2011 at 7:06 PM

I've added a new page:

please let me know if this is helpful for you