✅ Dealing/resolving nullable warnings
I try to deal with nullable warnings among others e. g. CS8604 "Possible null reference argument for parameter."
I have the following sample code of a C# 7.0 worker service:
Is that so well solved that you always check for is not null?
5 Replies
I suggest not extracting your null checks into a separate method. If you want a cleaner look, you can use Guards from the communitytoolkit by microsoft
Or just use plain old if statements
The logging of the issue should be done higher - once the exception is caught, you log the issue
Because this way you lose information as to what requirement was not met
and you make it more difficult for yourself this way
Guard - .NET Community Toolkit
Helper methods to verify conditions when running code
I think Guard will give you the clean look you are looking for, Microsoft uses it
Okay the guard class is really very cool. I try to use it
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.