Fix custom attribute with enum on generic type #827

Merged
vitek-karas merged 2 commits from EnumOnGenericAsAttributeValue into master 2022-02-21 17:07:22 -06:00
vitek-karas commented 2022-02-01 10:19:31 -06:00 (Migrated from github.com)

Fixes both the reader and the write to correctly handle values of type enum on a generic type.
Cecil represents generic instantiations as typeref which has etype GenericInst, so the exising check for etype doesn't work. Also since attributes only allow simple values and enums (and types), there's technically no other way to get a GenericInst then the enum case.

Added several test for various combinations of boxed an unboxed enums on generic type.

Added a test case provided by @mrvoorhe with array of such enums.

Fixes #804

Fixes both the reader and the write to correctly handle values of type enum on a generic type. Cecil represents generic instantiations as typeref which has etype GenericInst, so the exising check for etype doesn't work. Also since attributes only allow simple values and enums (and types), there's technically no other way to get a GenericInst then the enum case. Added several test for various combinations of boxed an unboxed enums on generic type. Added a test case provided by @mrvoorhe with array of such enums. Fixes #804
vitek-karas commented 2022-02-01 11:48:55 -06:00 (Migrated from github.com)

Had to disable the new tests when targeting .NET Framework. The tests are using CodeDOM compiler in that case and it doesn't support parsing enums on generic type as attribute arguments. I don't think the tests are important enough to try to rework how the tests are working on .NET Framework and make them use Roslyn there as well.

Had to disable the new tests when targeting .NET Framework. The tests are using CodeDOM compiler in that case and it doesn't support parsing enums on generic type as attribute arguments. I don't think the tests are important enough to try to rework how the tests are working on .NET Framework and make them use Roslyn there as well.
jbevain (Migrated from github.com) approved these changes 2022-02-21 17:06:37 -06:00
jbevain commented 2022-02-21 17:06:49 -06:00 (Migrated from github.com)

Beautiful, thank you!

Beautiful, thank you!
Sign in to join this conversation.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil!827
No description provided.