Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate object-object mapping in VS/Resharper

Is there any tools/plugins that can generate "manual" mapping code in VS/Resharper. I.e. there are 2 classes (Foo & Bar) with the same properties set:

{
    public string A { get; set; }
    public int B { get; set; }
    public decimal C { get; set; }
}

Is it possible to generate the following code somehow?

public Bar Create(Foo foo)
{
    var bar = new Bar();
    bar.A = foo.A;
    bar.B = foo.B;
    bar.C = foo.C;
    return bar;
}

Avoid mapping tools like AutoMapper, EmitMapper, etc.

like image 501
cycaHuH Avatar asked Oct 07 '13 17:10

cycaHuH


1 Answers

Yes, you can write a T4 template to scan the classes in your project and generate the desired code

like image 79
Elie Avatar answered Nov 03 '22 10:11

Elie