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

Nullable enum to int? #89

Closed OmiCron07 closed 5 years ago

OmiCron07 commented 5 years ago

I generated the following mapping :

bendingTypeDetail = new BendingTypeDetail
                    {
                      TypeNumber = args.BendingTypeDetail.TypeNumber,
                      Definition = (int) args.BendingTypeDetail.Definition,
                      Threads = new int?(value: (int) args.BendingTypeDetail.Threads.Value),
                    };

The field Definition is an enum and it has been converted right in an int. But the conversion of the field Threads, which is a nullable enum converted to nullable int, is invalid and will likely generate a null exception.

Should has been Threads = (int?) args.BendingTypeDetail.Threads

cezarypiatek commented 5 years ago

You are right. Thanks for reporting this issue, I will try to fix it.

cezarypiatek commented 5 years ago

Here is a version with fix: https://ci.appveyor.com/api/buildjobs/r36cais6plavwx9c/artifacts/MappingGenerator%2FMappingGenerator%2FMappingGenerator.Vsix%2Fbin%2FRelease%2FMappingGenerator.vsix

Would you mind to test it and let me know if everything works according to your expectations?

OmiCron07 commented 5 years ago

Seems all good 👍