Enums Constraint for Generics
Sometimes I have found my self in the need of doint something like:
where TEnum : Enum
... which currently is not possible.
Workarounds for this do exist, like:
where TEnum : struct, IConvertible
... but it could lead to bugs if not used with care.
Hope a new constraint for enums could make it for .NET 5.
Thanks for reading.
Thanks for taking the time to share this suggestion. This item has been around for a couple of versions of Visual Studio and we haven’t acted on it. Looking at the VS “15” plans, we’re not going to take action on this item, so we’re going to close it. If the suggestion is still relevant, please either take a look to see if there’s another suggestion that’s similar that you can vote on, or open a new suggestion.
- The Visual Studio Team
Robird Liu commented
It's useful and possible in implementation. Can't agree more.
Michel Bretschneider commented
How about joining forces? As there are some suggestions for enum constraints, why not vote for the one most likely to be noticed - the one with most votes so far. See: https://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2277087-add-in-support-for-enum-and-delegate-constraints
Maybe it's even possible to merge both suggestions without having all voters to switch their vote.
Matthieu Penant commented
See also http://stackoverflow.com/questions/7244/anyone-know-a-good-workaround-for-the-lack-of-an-enum-generic-constraint for reference. That would be a nice built-in feature.