jbevain / cecil

Cecil is a library to inspect, modify and create .NET programs and libraries.
MIT License
2.76k stars 627 forks source link

Fix custom attribute with enum on generic type #827

Closed vitek-karas closed 2 years ago

vitek-karas commented 2 years ago

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 2 years ago

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 commented 2 years ago

Beautiful, thank you!