You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enum.IsDefined(typeof(MyEnum), argument) is also quite slow as it needs to do lots of conversion checks etc; whereas if you already have the enum these don't need to be done.
I apologize for the shameless plug but I believe this is pertinent to users. I've just released version 1.0.0 of Enums.NET, a high-performance type-safe .NET enum utility library.
It has the extension method IsDefined that is constrained to the enum type which addresses this issue.
It also has the extension method IsValid that for flag enums checks if it's a valid combination of the defined flags or for standard enums checks if it's defined.
Enums.NET is available on NuGet and is compatible with .NET Standard 1.0+ as well as .NET Framework 2.0+.
Activity
[-]Add Enum.IsDefined() method[/-][+][Proposal] Add Enum.IsDefined() method[/+]TylerBrinkley commentedon Nov 5, 2016
I apologize for the shameless plug but I believe this is pertinent to users. I've just released version 1.0.0 of Enums.NET, a high-performance type-safe .NET enum utility library.
It has the extension method
IsDefinedthat is constrained to the enum type which addresses this issue.It also has the extension method
IsValidthat for flag enums checks if it's a valid combination of the defined flags or for standard enums checks if it's defined.Enums.NET is available on NuGet and is compatible with .NET Standard 1.0+ as well as .NET Framework 2.0+.
AlexGhiondea commentedon Nov 30, 2016
This is something we should consider.
The next step would be to have a formal API proposal written and have it reviewed.
TylerBrinkley commentedon Jan 25, 2017
I've created a formal API proposal dotnet/corefx#15453 that addresses this request.