How can I set my null-checking method to satisfy the warning "possible 'null' assignment to entity marked with 'NotNull' attribute"
I have an overload function for string to make it slightly easier to check if a string has been populated.
public static bool IsNullOrWhitespace(this string source) { return string.IsNullOrWhiteSpace(source); }
When I use this on variable, then use that variable as a [NotNull] paramater in a method call, I get the warning "possible 'null' assignment to entity marked with 'NotNull' attribute." Directly calling string.IsNullOrWhiteSpace(source) keeps the warning from showing up. Is there a way I can tell ReSharper that my method is a valid check for null?
Please sign in to leave a comment.
You need to add the ContractAnnotationAttribute to your method:
That did the trick, Richard. Thanks!
Is there any way to do this with Null Checking Patterns so that we are not dependent on annotations?
I'll duplicate Richard's answer here: https://resharper-support.jetbrains.com/hc/en-us/community/posts/6722297112594/comments/6729176732050