How to suppress "Formatting is specified but argument is not IFormattable" message for special methods

ReSharpers `StringFormatMethodAttribute` is a great way to keep track of the arguments on methods which perform string formatting.

So I implemented a method that way:

    [StringFormatMethod("format")]
    public string Format(string format, params object[] args)
    {
        // do formatting by custom formatters
    }


This gives me the ability to do things like that

    Format("Hello {0}!", world);      // => Hello world!
    Format("({0:D2} / {1:D2}", 2, 3); // => (02/03)


or in Visual Basic

    Format("Hello {0}!", visualBasic) ' => Hello Visual Basic!

while ReSharper warns me if I miss an argument or its position like so

    Format("Hello {1}!", world);
                           // ^--- Non-existing argument in format string


    Format("Hello {1}!", world, value);
                           // ^--- Argument is not used in format string


The method is using an `ICustomFormatter` so if I'd do this directly

    string.Format(customFormatter, "The thread id is {0:D}", Thread.CurrentThread);

ReSharper does not complain.

Using my method, which uses the custom formatting internally however, makes ReSharper complain with a warning

    Format("The thread id is {0:D}", Thread.CurrentThread);
                                               // ^--- Formatting is specified,
                                               //      but argument is not IFormattable


I don't want to disable this warnings in general, only the formatting issue part and if possible only for my own written methods. So my question is, is there a way, maybe by another attribute to make ReSharper aware, that this method is using a custom formatter internally?

1 comment
Comment actions Permalink

Unfortunately, you can't disable this analysis. I've added a feature request, which you can vote for, track and add any extra details: https://youtrack.jetbrains.com/issue/RSRP-450291

0

Please sign in to leave a comment.