string.Format highlighting for any method

  Here's an idea - in methods like string.format or Debug.WriteLine ReSharper is highlighting placeholders and invalid or missing parameters. This is sadly not available for custom methods wrapping string.format but with a similar signature.
I got an idea how to fix this - what about adding some kind of method attribute to notify ReSharper that a specific method is string.Format wrapper and should be highlihted, like:

[StringFormat]
public void Log(string format, params object args[])
{
...
}

  And then when I use Log("call {0}", data) somewhere, ReSharper will show me highliting and hints for such methods.
What do you think about this idea?

4 comments
Comment actions Permalink

Actually, there is an attribute that you can use:  StringFormatMethodAttribute.  This is one of the code annotation attributes.  You can either include the JetBrains.Annotations assembly or, if consuming a third party assembly is not to your taste (as it is in most companies) then go to Resharper -> Options -> Code Inspection -> Code Annotations, click on "Copy default implementation to clickboard".  Paste the code into a code file, change the namespaces to fit your requirements and use.

0
Comment actions Permalink

Ha, it works, thanks! Is there any article how to use all these Annotation attributes?

0
Comment actions Permalink

is it an intention that if i uncheck the "JetBrains.Annotations" namespace in the Options/Code Annotations, the StringFormatMethodAttribute seem doesn't work anymore?
Hint: I have an additional Annotations customized namespace created with copy/paste of default implementation. R# 7.1.8 EAP

0

Please sign in to leave a comment.