-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Enum validation #111018
Comments
Put it in InvalidEnumArgumentException instead? |
For InvalidEnumArgumentException, it was previously rejected in #83107 and #92071 because Enum.IsDefined is slower than |
The performance might be fixable by making the JIT and Native AOT compilers generate dedicated code for each enum type. This would not solve the application compatibility with new enum values, though. A source generator (perhaps with an interceptor) could be another option. If the source were generated in an application that uses an enum type defined in a library, then the set of recognised values would depend on which version of the library was referenced at build time, rather than the version used at run time. I'm not sure that would be an improvement. |
Yes it's a tricky situation. The simplest solution is "to do nothing" as mentioned in that other thread. i.e. manual validation of specific values, or if one is sure of the consequences, to use |
Background and motivation
There is a large assortment of input validation methods, e.g.
ArgumentNullException.ThrowIfNull
,ArgumentOutOfRange.ThrowIfNegative
, etc.Most fundamental use cases are covered, except for enum validation.
API Proposal
API Usage
Alternative Designs
n/a
Risks
n/a
Thanks for considering it!
The text was updated successfully, but these errors were encountered: