Adding Resharper code annotation to own code in a non-invasive manner

c#, resharper, syntax-highlighting

Solution

You don't have to reference the assembly to add annotation attributes. As per the documentation, you can go to `ReSharper/Options/Code Annotations`, copy the attribute implementations to the clipboard, and paste them into your own source, where ReSharper will use them. You can even change the namespace they're in if you'd prefer not to have `JetBrains` in your assembly.

I don't know whether you'll have any luck using external (XML) annotations for source code, though. I get the impression they're only for existing binaries. That said, I think that decorating your source with attributes is quite valuable as a source of documentation for yourself and other developers.

Problem

I want to flag one of my methods with the StringFormatMethod attribute so Resharper syntax highlights it. I was able to do this by referencing the JerBrains.Annotations assembly and adding the attribute. However I find this to be a very invasive way to do this. Not everybody here uses JetBrains and it will require committing the .dll to subversion, adding the dependency and littering the code with something that is specific to a particular IDE, which I hate. I read about the "external annotations" feature, but I wasn't able to do it. I'm not sure if I did it wrong or if it's simply not supported for a project inside the solution (i.e not a compiled assembly reference). So is there a way to add a code annotation to a method in the project in a non-invasive way? P.S this is the method: using System; ``` namespace MyLib { public static class Assert { public static void That(bool condition, string format, params object[] @params) { if (!condition) throw new Exception(string.Format(format, @params)); } } } ``` And this is the contents of C:\Program Files (x86)\JetBrains\ReSharper\v7.1\Bin\ExternalAnnotations\MyLib.xml: ``` <assembley name="MyLib"> <member name="MyLib.Assert.That(System.Boolean,System.String,System.Object[])"> <attribute ctor="M:JetBrains.Annotations.StringFormatMethodAttribute.#ctor"> <argument>format</argument> </attribute> </member> </assembley> ```

Original source