How to tell R# that a function is a null-test?

So I have this extension method..

public static bool IsNullOrWhiteSpace(this string @this) { return string.IsNullOrWhiteSpace(@this); }

If I do this:
if (string.IsNullOrWhiteSpace(myString)) return

then R# knows that later use of the string will be non-null. Yet if I instead use my extension method
if (myString.IsNullOrWhiteSpace()) return

it does not change R#'s knowledge of the null state of the string.

How does R# know that string.IsNullOrWhiteSpace() does a null-test internally? And is there a way I can tell it about my extension method as well? Perhaps with attributes or modifying an xml file or something?
1 comment
Comment actions Permalink


You have to add some Attributes (located in Jetbrains.Annotations.dll or copy the sourcode in a own class via the resharper options dialog) to your methods.
Our method looks like this

public static void NotNull<T>([AssertionCondition(AssertionConditionType.IsNotNull), NoEnumerationAttribute]T value, [LocalizationRequired(false), InvokerParameterName] string parameterName) where T : class {
     if (value == null) {
          throw new ArgumentNullException(parameterName);


Please sign in to leave a comment.