Closed OmiCron07 closed 4 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).
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?
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?
If the target or source property is already used, skip it?
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.
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.
When using the MappginGenerator, I lose my properties UnitId/InventoryUnitId and Category/UnitCategory:
Is it possible to detect slight variation in property name or at least not overriding the entire method and keeping my unmatched properties?