DustinCampbell / CSharpEssentials

C# Essentials is a collection of Roslyn diagnostic analyzers, code fixes and refactorings that make it easy to work with C# 6 language features.
Other
160 stars 26 forks source link

Add support for string interpolation conversions on user-defined methods #21

Open DustinCampbell opened 9 years ago

DustinCampbell commented 9 years ago

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) { ... }
pharring commented 9 years ago

Where does that attribute come from?

fsateler commented 9 years ago

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

Bryan-Legend commented 9 years ago

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