Two more reserved attributes for easier error handling #4623
Replies: 3 comments 4 replies
-
See: #287 |
Beta Was this translation helpful? Give feedback.
-
There's already an annotation that achieves the null side of this. Put |
Beta Was this translation helpful? Give feedback.
-
Thanks for the answers. Perhaps https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.codeanalysis.notnullattribute?view=net-5.0 should be expanded with an example or better clarification. It's exactly what I asked for, but I didn't understand that from the documentation. (This issue can be closed.) |
Beta Was this translation helpful? Give feedback.
-
Two more reserved attributes for easier error handling
A common pattern is to use Throw helpers for generating consistent error checks and error messages.
An example:
And is called like this:
This example has two problems:
Suggestion 1: Add a new attribute to indicate that a function does not return if an argument is null or empty:
or
Suggestion 2: Add a new attribute that gets the source code from a parameter like
CallerMemberNameAttribute
returns the calling function name. The(0)
indicates which parameter to get.So
Lowers to:
Or
Lowers to:
Beta Was this translation helpful? Give feedback.
All reactions