linkdotnet/StringBuilder

Add `AppendFormat` methods

linkdotnet opened this issue · 0 comments

The System.Text.StringBuilder offers some AppendFormat methods that make life easier if you want to format your values:

var sb = new StringBuilder();
sb.AppendFormat("{0} + {1} = {2}", 1, 2, 3);

It would be nice to have the same set of methods for the ValueStringBuilder. One major difference would be that the ValueStringBuilder would offer non-boxed versions:

public ref struct ValueStringBuilder
{
    public void AppendFormat<T>(ReadOnlySpan<char> format, T arg1);
    public void AppendFormat<T1, T2>(ReadOnlySpan<char> format, T1 arg1, T2 arg2);
    public void AppendFormat<T1, T2, T3>(ReadOnlySpan<char> format, T1 arg1, T2 arg2, T3 arg3);
    // ...
}

We want to avoid boxing and unboxing as much as possible. Still, there can be a convenient function that takes a params object[] as input (maybe it should have a different naming to indicate the boxing/unboxing nature).