Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Jan 13, 2024
1 parent 6ccf6cb commit d47077a
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
6 changes: 6 additions & 0 deletions api_list.include.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,12 @@
* `StringBuilder Append(ReadOnlySpan<Char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-readonlyspan((system-char))))
* `StringBuilder Append(AppendInterpolatedStringHandler&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-appendinterpolatedstringhandler@))
* `StringBuilder Append(IFormatProvider, AppendInterpolatedStringHandler&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-iformatprovider-system-text-stringbuilder-appendinterpolatedstringhandler@))
* `StringBuilder AppendJoin(String, String[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-string-system-string()))
* `StringBuilder AppendJoin(String, Object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-string-system-object()))
* `StringBuilder AppendJoin(Char, String[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-char-system-string()))
* `StringBuilder AppendJoin(Char, Object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-char-system-object()))
* `StringBuilder AppendJoin<T>(Char, T[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin-1(system-char-system-collections-generic-ienumerable((-0))))
* `StringBuilder AppendJoin<T>(String, T[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin-1(system-string-system-collections-generic-ienumerable((-0))))
* `StringBuilder AppendLine(AppendInterpolatedStringHandler&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendline#system-text-stringbuilder-appendline(system-text-stringbuilder-appendinterpolatedstringhandler@))
* `StringBuilder AppendLine(IFormatProvider, AppendInterpolatedStringHandler&)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendline#system-text-stringbuilder-appendline(system-iformatprovider-system-text-stringbuilder-appendinterpolatedstringhandler@))
* `Void CopyTo(Int32, Span<Char>, Int32)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.copyto#system-text-stringbuilder-copyto(system-int32-system-span((system-char))-system-int32))
Expand Down
73 changes: 73 additions & 0 deletions src/Polyfill/Polyfill_StringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public static bool Equals(this StringBuilder target, ReadOnlySpan<char> span)
}

#endif

#if HAS_SPAN && !NET6_0_OR_GREATER
/// <summary>Appends the specified interpolated string to this instance.</summary>
/// <param name="handler">The interpolated string to append.</param>
Expand Down Expand Up @@ -144,7 +145,9 @@ public static StringBuilder AppendLine(
IFormatProvider? provider,
[InterpolatedStringHandlerArgument(nameof(target), nameof(provider))] ref AppendInterpolatedStringHandler handler) =>
target.AppendLine();

#elif NET6_0_OR_GREATER

/// <summary>Appends the specified interpolated string to this instance.</summary>
/// <param name="handler">The interpolated string to append.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
Expand Down Expand Up @@ -184,5 +187,75 @@ public static StringBuilder AppendLine(
IFormatProvider? provider,
[InterpolatedStringHandlerArgument(nameof(target), nameof(provider))] ref StringBuilder.AppendInterpolatedStringHandler handler) =>
target.AppendLine(provider, ref handler);
#endif

#if NETSTANDARD2_0|| NETFRAMEWORK

/// <summary>Concatenates the strings of the provided array, using the specified separator between each string, then appends the result to the current instance of the string builder.</summary>
/// <param name="separator">The string to use as a separator. separator is included in the joined strings only if values has more than one element.</param>
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-string-system-string())")]
public static StringBuilder AppendJoin(
this StringBuilder target,
string separator,
params string[] values) =>
target.Append(string.Join(separator, values));

/// <summary>Concatenates the string representations of the elements in the provided array of objects, using the specified separator between each member, then appends the result to the current instance of the string builder.</summary>
/// <param name="separator">The string to use as a separator. separator is included in the joined strings only if values has more than one element.</param>
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-string-system-object())")]
public static StringBuilder AppendJoin(
this StringBuilder target,
string separator,
params Object[] values) =>
target.Append(string.Join(separator, values));

/// <summary>Concatenates the strings of the provided array, using the specified char separator between each string, then appends the result to the current instance of the string builder.</summary>
/// <param name="separator">The character to use as a separator. separator is included in the joined strings only if values has more than one element.</param>
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-char-system-string())")]
public static StringBuilder AppendJoin(
this StringBuilder target,
char separator,
params string[] values) =>
target.Append(string.Join(separator.ToString(), values));

/// <summary>Concatenates the string representations of the elements in the provided array of objects, using the specified char separator between each member, then appends the result to the current instance of the string builder.</summary>
/// <param name="separator">The character to use as a separator. separator is included in the joined strings only if values has more than one element.</param>
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin(system-char-system-object())")]
public static StringBuilder AppendJoin(
this StringBuilder target,
char separator,
params object[] values) =>
target.Append(string.Join(separator.ToString(), values));

/// <summary>Concatenates and appends the members of a collection, using the specified char separator between each member.</summary>
/// <param name="separator">The character to use as a separator. separator is included in the joined strings only if values has more than one element.</param>
/// <param name="values">A collection that contains the objects to concatenate and append to the current instance of the string builder.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin-1(system-char-system-collections-generic-ienumerable((-0)))")]
public static StringBuilder AppendJoin<T>(
this StringBuilder target,
char separator,
params T[] values) =>
target.Append(string.Join(separator.ToString(), values));

/// <summary>Concatenates and appends the members of a collection, using the specified char separator between each member.</summary>
/// <param name="separator">The string to use as a separator. separator is included in the concatenated and appended strings only if values has more than one element.</param>
/// <param name="values">A collection that contains the objects to concatenate and append to the current instance of the string builder.</param>
/// <returns>A reference to this instance after the append operation has completed.</returns>
[Link("https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin?view=netcore-2.0#system-text-stringbuilder-appendjoin-1(system-string-system-collections-generic-ienumerable((-0)))")]
public static StringBuilder AppendJoin<T>(
this StringBuilder target,
string separator,
params T[] values) =>
target.Append(string.Join(separator.ToString(), values));

#endif
}
2 changes: 0 additions & 2 deletions src/Tests/PolyfillTests_StringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public void AppendWithFormat()
Polyfill.Append(builder, null, $"value{x}");
Assert.AreEqual("value10", builder.ToString());
}
#if NET8_0

[Test]
public void AppendJoin()
Expand All @@ -69,5 +68,4 @@ void Assert()
builder.Clear();
}
}
#endif
}

0 comments on commit d47077a

Please sign in to comment.