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

Base class properties not mapped #30

Closed phoenix172 closed 6 years ago

phoenix172 commented 6 years ago

I have a class ChildModel inheriting from ModelBase which contains an Id property and a class Child inheriting from Entity which also contains an Id property of the same type. When I try to generate a mapping from Child to ChildModel all properties are mapped except the Id property.

It is not difficult to add it manually in my case but if there were more properties it would become a bit annoying. I don't know if this is intended behavior or just something you haven't thought about.

UPDATE: I just noticed something else. Curiously enough, when I generate code for the opposite mapping i.e ChildModel to Child, I do get mapping code for the Id property.

cezarypiatek commented 6 years ago

Mapping properties from inherited class should be supported. Could you show code of your classes?

phoenix172 commented 6 years ago

Child Entity image

Person Entity image

Entity image

Child Model image

Model Base image

When I try to generate mapping from Child Entity to Child Model, I get this(ignore the recursion code - this is just an illustration): image

And when I do it the other way round - Child Model to Child Entity, this is the result: image

Notice that in the first case there isn't an Id column mapping, while in the second there is. Maybe I am doing something wrong?

cezarypiatek commented 6 years ago

Are these classes in the same assembly?

phoenix172 commented 6 years ago

Yes, they are. Just different namespaces.

cezarypiatek commented 6 years ago

Ok, I've just found the culprit, ModelBase.Id has setter with internal modifier. I need to handle this case. but it can take a while. I have no idea how to check if element with internal modifier is accessible in given context.

cezarypiatek commented 6 years ago

I've found code that check if two types are from different assemblies but this requires a lot of changes because we need to pass context of code generation https://github.com/dotnet/roslyn/blob/master/src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions_Accessibility.cs

cezarypiatek commented 6 years ago

@phoenix172 Could you test this version https://ci.appveyor.com/api/buildjobs/v2ooime65b205pff/artifacts/MappingGenerator%2FMappingGenerator%2FMappingGenerator.Vsix%2Fbin%2FRelease%2FMappingGenerator.vsix and tell me if all mappings works correctly?

phoenix172 commented 6 years ago

Confirmed working. Nice job and thank you :)

phoenix172 commented 6 years ago

I guess you would want to close this with a commit :)

phoenix172 commented 6 years ago

Oh just found a new problem that I am not sure was present with the old version.

The Generate Mapping option does not appear when the cursor is at the end of the method name. 2018-08-25_19-00-47

If this is not just the new version, I can open a separate issue.

cezarypiatek commented 6 years ago

This problem is not related with the original issue but there is no need to create another ticket. I will check that tomorrow.

cezarypiatek commented 6 years ago

@phoenix172 would you be so kind to test the new version? https://ci.appveyor.com/api/buildjobs/mnxgommposnkhw7q/artifacts/MappingGenerator%2FMappingGenerator%2FMappingGenerator.Vsix%2Fbin%2FRelease%2FMappingGenerator.vsix

phoenix172 commented 6 years ago

Works great :)

cezarypiatek commented 6 years ago

Thanks for testing. Fix merged into develop, should be released in few days.