I have a method that turns string.IsNullOrWhiteSpace(string value) into an extension method.
public static bool IsNullOrWhitespace(this string source)
{
return string.IsNullOrWhiteSpace(source);
}
After I use this to check for null, Resharper still warns me that the variable I'm passing as a [NotNull] argument might be null.
"Possible 'null' assignment to entity marked with 'NotNull' attribute"
If I replace my use (str.IsNullOrWhiteSpace()) with the original (string.IsNullOrWhiteSpace(str)), the warning doesn't show up.
Is there a way with Resharper that I can train it to know that my extension method is a valid null checker so that this null assignment warning doesn't show up?
Note:
- I don't want to hide it with //resharper disable comments everwhere.
- I don't want to disable it entirely, as it should show up when I'm not null-checking.
Edit:
There's a property in the JetBrains.Annotations NuGet package called ContractAnnotation that does the trick.
[ContractAnnotation("source:null => true")]
public static bool IsNullOrWhitespace(this string source)
{
return string.IsNullOrWhiteSpace(source);
}
This does the trick.
Found it!
There's a property in the JetBrains.Annotations NuGet package called ContractAnnotation that does the trick.
This does the trick.