Available in Resharper 7 and later
[ContractAnnotation("null=>true")] public static bool IsNullOrWhiteSpace(this string s)
Your project will not know what ContractAnnotation . You need to add it to your project. The preferred method is nuget:
PM> Install-Package JetBrains.Annotations
Alternatively, you can directly embed the source in your project:
Resharper -> Options -> Code Annotations -> Copy the default implementation to the clipboard
Then paste this into a new file, for example Annotations.cs. The definition of ContractAnnotation is in this file. For an official article on ContractAnnotation, see here .
Previous answer (for versions without R # 7)
Is it hardcoded in R #?
No, Resharper uses external annotations to provide this feature. This article should answer all your questions, including a solution for providing your own external annotation for your IsNullOrWhiteSpace method.
Example
Note: external annotations seem to work only in reference libraries; if your link is related to the project, external annotations are not selected; it's less than ideal
Suppose you have an extension method in a class called TempExtensions , which itself is in an assembly called ClassLibrary1
You need to add a new file in this place.
C: \ Program Files (x86) \ JetBrains \ ReSharper \ v7.0 \ Bin \ ExternalAnnotations.NETFramework.ExternalAnnotations \ ClassLibrary1 \ ClassLibrary1.xml
The xml content 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=>true</argument> <argument>true</argument> </attribute> </member> </assembly>