CSharpEssentials
CSharpEssentials copied to clipboard
Add string interpolation conversions for other common .NET APIs
It'd be great to be able to apply the "Convert to String Interpolation" to .NET APIs other than just String.Format(). For example:
- Debug.WriteLine(string, params object[])
- Console.WriteLine(string, params object[])
- StringBuilder.AppendFormat() (even though this causes an allocation)
Add to the list TextWriter.Write and TextWriter.WriteLine
Or user-defined methods as well.
@fsateler, Do you have a proposal for how that might be detected? Requiring a parameter of type string and a parameter of object[] seems too permissive.
@DustinCampbell I think the only reasonable way is to require annotation with an attribute. This would also allow formatters that require extra parameters:
[FormatStringConsumer(FormatStringParameterNumber = 2)]
void WriteToDevice(Device d, string format, params object[] arguments) { ... }
Nice idea! Should probably be a separate issue though. Added #21 to capture this.