Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h1>Available in Resharper 7 and above</h1> <pre><code>[ContractAnnotation("null=&gt;true")] public static bool IsNullOrWhiteSpace(this string s) </code></pre> <p>Your project isn't going to know what <code>ContractAnnotation</code> is. You need to add it to your project. The preferred method is via nuget:</p> <blockquote> <p>PM> Install-Package <a href="https://www.nuget.org/packages/JetBrains.Annotations" rel="nofollow">JetBrains.Annotations</a></p> </blockquote> <p>Alternatively you can directly embed the source into your project:</p> <blockquote> <p>Resharper -> Options -> Code Annotations -> Copy default implementation to clipboard</p> </blockquote> <p>Then paste that into a new file, eg Annotations.cs. The <code>ContractAnnotation</code> definition lives in that file. For an official article on ContractAnnotation see <a href="http://blogs.jetbrains.com/dotnet/2012/08/contract-annotations-in-resharper-7/" rel="nofollow">here</a></p> <hr> <h2>Previous answer (for non R#7 versions)</h2> <blockquote> <p>Is this hardcoded in R#?</p> </blockquote> <p>No, Resharper uses External Annotations to provide this functionality. <a href="http://blogs.jetbrains.com/dotnet/2010/11/resharper-nullreferenceexception-analysis-and-its-contracts/" rel="nofollow">This article</a> should answer all your questions, including a solution to provide your own external annotation for your <code>IsNullOrWhiteSpace</code> method.</p> <h3>Example</h3> <p><em>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</em></p> <p>Suppose you have your extension method in a class called <code>TempExtensions</code> which itself resides in an assembly named <code>ClassLibrary1</code></p> <p>You need to add a new file at this location</p> <blockquote> <p>C:\Program Files (x86)\JetBrains\ReSharper\v7.0\Bin\ExternalAnnotations.NETFramework.ExternalAnnotations\ClassLibrary1\ClassLibrary1.xml</p> </blockquote> <p>The contents of the xml should contain:</p> <pre><code>&lt;assembly name="ClassLibrary1"&gt; &lt;member name="M:ClassLibrary1.TempExtensions.IsNullOrWhiteSpace(System.String)"&gt; &lt;attribute ctor="M:JetBrains.Annotations.ContractAnnotationAttribute.#ctor(System.String,System.Boolean)"&gt; &lt;argument&gt;null=&amp;gt;true&lt;/argument&gt; &lt;argument&gt;true&lt;/argument&gt; &lt;/attribute&gt; &lt;/member&gt; &lt;/assembly&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload