Extend code analysis for params parameter to other methods than string/StringBuilder?

[5.1.1757]

Is it possible somehow (via files/structured find/replace) to extend the RS warnings for other methods using the params parameter (eg. log4net's DebugFormat, WarningFormat  etc.)?
I've noticed the RS code analysis works properly for both string.Format(...) and StringBuilder.AppendFormat(...).
(Found a 3 years old feature request for a similar issue - http://youtrack.jetbrains.net/issue/RSRP-40358 "User attribute enables warning on custom method parameters with same semantics as string.Format(...)").

Thanks.

3 comments
Comment actions Permalink

Hello,

Theres a StringFormatMethod attribute in ReSharper annotations, that can
be used to mark such methods. You can create external annotations under \Bin\ExternalAnnotations if the format method is located in a
third-party library. Please note that corresponding annotations for log4net
should be already there. Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"



Is it possible somehow (via files/structured find/replace) to extend
the RS warnings for other methods using the params parameter (eg.
log4net's DebugFormat, WarningFormat  etc.)?

I've noticed the RS code analysis works properly for both
string.Format(...) and StringBuilder.AppendFormat(...).

(Found a 3 years old feature request for a similar issue -
http://youtrack.jetbrains.net/issue/RSRP-40358 "User attribute enables
warning on custom method parameters with same semantics as
string.Format(...)").

Thanks.

---
Original message URL:
http://devnet.jetbrains.net/message/5278485#5278485



0
Comment actions Permalink

Yes, it's possible with code annotation.
You can reference JetBrains.Annotations.dll assembly with necessary attributes or just copy their implementations to your project through ReShaper->Options->Code Annotations.
You need to use StringFormatMethodAttribute, i.e.

[StringFormatMethod("myFormatString")]
public string MyFormat(string myFormatString, params object[] data)
{
  ...
}



If you need apply this attribute to not your code, for example, log4net, you can do it by using External Annotation feature.

By the way, log4net already marked up by necessary attributes by JetBrains itself.
0

Please sign in to leave a comment.