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

Generate mapping returns new class without mapping - support for field mapping #94

Closed imtrobin closed 4 years ago

imtrobin commented 4 years ago

Hi, is there some requirements of the map to work? I tried on my class, the "Generate mapping" part just shows new Class () without mapping the members. E.g.

public static  YYY   CreateYYYFromXXX (XXX x)
{
  // nothing is mapped
   returns new YYY ();
}
cezarypiatek commented 4 years ago

Hi @imtrobin, Can you show YYY and XXX classes' definitions?

imtrobin commented 4 years ago
public class XXX
 {
        public string Name             = null;
        public string Description      = null;
        public HashSet <string> Hashes            = null;
}

public class YYY
    {
        public string ID    = null;
        public string Name             = null;
        public string Description      = null;

        public HashSet <string> Hashes            = null;
         public DateTime TimeCreated      = DateTime.MinValue;
}
cezarypiatek commented 4 years ago

Currently, MappingGenerator is using properties to determine the source and destination of mapping. Is there any particular reason why you prefer fields over properties?

imtrobin commented 4 years ago

I see. I do not need c# properties get/set so I chose with simple fields since it is always public get/set

cezarypiatek commented 4 years ago

Since C# 3.0, when auto-implemented properties had been introduced, they should be a default choice.
I can't see any specific reason why this language relict should be supported - of course, PR with the implementation of this functionality is welcome.

imtrobin commented 4 years ago

These are just simple classes to map rest requests. I do use properties in other places, where needed. Will add it to my todo list. I presume you are using reflection so it should fairly easy to get member vars.

cezarypiatek commented 4 years ago

MappingGenerator is not using reflection. It's completely based on the Roslyn and SyntaxTree analysis.

imtrobin commented 4 years ago

Oh bummer, not familiar with that.

cezarypiatek commented 4 years ago

I'm working on it but I can't promise when this will be released (I need to refactor a couple of things before to keep the codebase still maintainable).

cezarypiatek commented 4 years ago

A new version 1.16.393 with this feature has been released. @imtrobin could you test it and let me know if this works as expected?

imtrobin commented 4 years ago

Hi cezary, seems to be working well, thanks!