cezarypiatek / MappingGenerator

:arrows_counterclockwise: "AutoMapper" like, Roslyn based, code fix provider that allows to generate mapping code in design time.
https://marketplace.visualstudio.com/items?itemName=54748ff9-45fc-43c2-8ec5-cf7912bc3b84.mappinggenerator
MIT License
1.03k stars 120 forks source link

Support for Expression<Func<in T, out TResult>> #34

Closed lindeberg closed 6 years ago

lindeberg commented 6 years ago

Hey! Awesome project. I too thought automapper got in the way in a large project.

I'd like to request a further feature. I'm working a lot with IQueryable projections and within those c# methods aren't really supported as far as I know?

So I make a few mapping expressions like this:

 public static Expression<Func<Core.Models.Entities.Member, QueryResult.Member>> Map = member => new Member
{
                FirstName = member.FirstName
};

which I then use like this:

var items = members
                .Select(QueryResult.Member.Map)
                .ToList();

I cannot find support for this feature atm and would really like to see it implemented :)

cezarypiatek commented 6 years ago

Hi

I'm not sure if I'm understanding requested feature correctly. For me it looks like #14 which has been implemented already. As I remember the diagnostic should be reported if you have empty initialization block as follows:

 public static Expression<Func<Core.Models.Entities.Member, QueryResult.Member>> Map = member => new Member
{

};

If you expect something different please provide a sample code before and after transformation for better understanding.

lindeberg commented 6 years ago

That's exactly what I was requesting, haha, awesome it's already implemented! Sorry, I just couldnt find it, I didn't which was the right spot to put the cursor i guess. Thanks!!

cezarypiatek commented 6 years ago

No problem, I'm glad I could help you out. I've updated readme with example for this functionality.