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

Loosing properties #12

Closed OmiCron07 closed 4 years ago

OmiCron07 commented 6 years ago

When using the MappginGenerator, I lose my properties UnitId/InventoryUnitId and Category/UnitCategory:

image

Is it possible to detect slight variation in property name or at least not overriding the entire method and keeping my unmatched properties?

cezarypiatek commented 6 years ago

I would like to keep mapping rules quite obvious and "detect slight variation in property name" could result in complicated logic and the outcome could be far away from expected for different use cases. The second option with not overriding entire method requires add some merging logic. I was thinking about adding option to assign default value for unmapped target fields which could help to spot places with naming discrepancy or missing fields. For now to avoid complete method overriding you can write line with assigning source to destination

public override void Convert(T1 source, T2 destination)
{
    destination = source;
}

and try to apply another code fix which comes with MaggingGenerator that create conversion (the bulb should appear in line with the assignment).

image

OmiCron07 commented 6 years ago

Ok, but the problem is maintainability. No way you generate the mapping once and never change it. Some properties will be added, some will be removed.

I can't imagine having to remove the code, writing target = source,, alt-enter, Generate, each time to update the mapping.

I know the problem is not trivial, but I need a tool to quickly generate mapping code and also, update the mapping efficiently.

What do you think?

cezarypiatek commented 6 years ago

I don't see the problem with maintainability. In most cases you add or remove single field, so it's not big effort to apply this simple modification manually instead of regenerating the whole mapping. What if in the meantime somebody add custom, non-trivial mapping logic? How am I supposed to detect that and perform merging during regeneration? How to decide if this modification is still valid and should survive the regeneration?

OmiCron07 commented 6 years ago

If the target or source property is already used, skip it?

cezarypiatek commented 6 years ago

sounds simple, and if the method flow is simple (no conditional or loop statements) it could work. Anyway I think it should be registered as separated code fix - with the update purpose.

cezarypiatek commented 4 years ago

I'm not going to implement a synchronization mechanism. If you need a mapping code that is continuously synchronized with models, please take a look at OnBuild plugin (#79) that generates mapping code during the build.