Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:25:10+00:00 2026-06-10T02:25:10+00:00

This is ReSharper 7 with Visual Studio 2012. With the sample below // This

  • 0

This is ReSharper 7 with Visual Studio 2012. With the sample below

// This code works fine and as expected and ReShrper is happy with it
if (!string.IsNullOrWhiteSpace(extension) && extension.Length == 3)
{
    // do something
}

// ReSharper highlights "extension" in extension.Length with "Possible 'System.NullReferenceException'"
if (!extension.IsNullOrWhiteSpace() && extension.Length == 3)
{
    // do something
}

And, I have created the following extension method:

public static class StringExtensions
{
    public static bool IsNullOrWhiteSpace(this string s)
    {
        return string.IsNullOrWhiteSpace(s);
    }
}

I looked at the reflected code of String.IsNullOrWhiteSpace and it doesn’t have any related code or attribute that would highlight to R# that the check is verified. Is this hardcoded in R#?

I looked at Code Contracts, but I am not sure it would help in my case.

Do you have a workaround for proving to ReSharper that the check condition is already verified by my extension method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:25:12+00:00Added an answer on June 10, 2026 at 2:25 am

    Available in Resharper 7 and above

    [ContractAnnotation("null=>true")]
    public static bool IsNullOrWhiteSpace(this string s)
    

    Your project isn’t going to know what ContractAnnotation is. You need to add it to your project. The preferred method is via nuget:

    PM> Install-Package JetBrains.Annotations

    Alternatively you can directly embed the source into your project:

    Resharper -> Options -> Code Annotations -> Copy default implementation to clipboard

    Then paste that into a new file, eg Annotations.cs. The ContractAnnotation definition lives in that file. For an official article on ContractAnnotation see here


    Previous answer (for non R#7 versions)

    Is this hardcoded in R#?

    No, Resharper uses External Annotations to provide this functionality. This article should answer all your questions, including a solution to provide your own external annotation for your IsNullOrWhiteSpace method.

    Example

    note: external annotations appear to only work on referenced libraries; if your reference is from a project the external annotations are not picked up; this is less than ideal

    Suppose you have your extension method in a class called TempExtensions which itself resides in an assembly named ClassLibrary1

    You need to add a new file at this location

    C:\Program Files (x86)\JetBrains\ReSharper\v7.0\Bin\ExternalAnnotations.NETFramework.ExternalAnnotations\ClassLibrary1\ClassLibrary1.xml

    The contents of the xml should contain:

    <assembly name="ClassLibrary1">
      <member name="M:ClassLibrary1.TempExtensions.IsNullOrWhiteSpace(System.String)">
        <attribute ctor="M:JetBrains.Annotations.ContractAnnotationAttribute.#ctor(System.String,System.Boolean)">
            <argument>null=&gt;true</argument>
            <argument>true</argument>
        </attribute>
      </member>
    </assembly>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does Visual Studio / Resharper support this? By refactor copy I mean to be
I used to see any .net source code (like System.String) with ReSharper and Visual
This is regarding Visual Studio pro 2008 sp1, with resharper and testdriven installed. I've
Help me replace this code, both me and Resharper don't like it: <table width=100%>
This is my code: <CheckBox android:id=@+id/sprint_checkbox android:layout_width=fill_parent android:layout_height=wrap_content android:text=@string/sprint_game /> <CheckBox android:id=@+id/marathon_checkbox android:layout_width=fill_parent android:layout_height=wrap_content
In Visual Studio with Resharper I can set the project to background build as
I primarily use Visual Studio and ReSharper (R#) for development and have excellent working
I've just started using ReSharper with Visual Studio (after the many recommendations on SO).
I'm using Resharper 4.5 with Visual Studio 2008 and MBUnit testing, and there seems
Recently, my Visual Studio 2008(with Resharper 4.5) has started to reformat asp tags into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.