CSharpEssentials icon indicating copy to clipboard operation
CSharpEssentials copied to clipboard

Add support for string interpolation conversions on user-defined methods

Open DustinCampbell opened this issue 9 years ago • 3 comments

Just wanted to capture the suggestion made by @fsateler in issue #19 to allow users to annotate their own methods with a custom attribute which would allow the Convert to String Interpolation refactoring to run on them:

[FormatStringConsumer(FormatStringParameterNumber = 2)]
 void WriteToDevice(Device d, string format, params object[] arguments) { ... }

DustinCampbell avatar Jul 22 '15 20:07 DustinCampbell

Where does that attribute come from?

pharring avatar Jul 22 '15 20:07 pharring

@pharring it should be defined by CSharp essentials. This would probably require to provide the nuget package (#15)

fsateler avatar Jul 22 '15 20:07 fsateler

Resharper defines a StringFormatMethodAttribute for this: http://www.jetbrains.com/resharper/help/Code_Analysis__String_Formatting_Methods.html

I've looked thru the .net framework in hopes of finding something built in and applicable, but couldn't find anything exact.

Perhaps we could use suppressmessageattribute to turn it on instead of off! https://msdn.microsoft.com/en-us/library/system.diagnostics.codeanalysis.suppressmessageattribute(v=vs.110).aspx

Maybe [Category("Format")] or [Category("StringFormatMethod")]? https://msdn.microsoft.com/en-us/library/system.componentmodel.categoryattribute.aspx?f=255&MSPPError=-2147217396

Bryan-Legend avatar Jul 28 '15 06:07 Bryan-Legend