External annotations
How it works
If you are using an external library, whose sources are not available to you, it does not seem feasible to use the attributes there for specifying code annotations.
In this case, you can use External Annotations, which allow you to complement the already compiled entities with attributes recognized by ReSharper for Visual Studio Code's code analysis engine. External annotations let you 'cheat' the engine, by making it see the attributes (for methods, parameters, and other declarations), which were not declared at the time the library was compiled.
External annotations are specified in XML files. When loading solution, ReSharper for Visual Studio Code looks for specifically named XML files in specific locations and reads annotations from there. These XML files have a structure similar to XmlDoc. For example, to annotate the method XmlReader.Create(Stream input) from the assembly System.Xml of .NET Framework 4.0, with the NotNull contracts, the XML file would look as follows:
JetBrains external annotations
The approach described above was used to annotate a huge amount of symbols in the .NET Framework Class Library, as well as in other frequently used libraries. External annotations for these libraries are installed with ReSharper for Visual Studio Code to ensure better code analysis. Some features (for example, ASP.NET MVC support) also rely on external annotations.
The source code of JetBrains external annotations is available under the MIT license on GitHub: https://github.com/JetBrains/ExternalAnnotations. You are welcome to contribute to this repository or use it as an example for your own external annotations.