Skip to content

Commit 044e4a6

Browse files
authored
add generic AppendJoin (#308)
1 parent 1c07af7 commit 044e4a6

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

apiCount.include.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
**API count: 522**
1+
**API count: 524**

api_list.include.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@
367367
* `StringBuilder Append(StringBuilder, 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@))
368368
* `StringBuilder Append(StringBuilder, StringBuilder.AppendInterpolatedStringHandler)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-appendinterpolatedstringhandler@))
369369
* `StringBuilder Append(StringBuilder, IFormatProvider?, StringBuilder.AppendInterpolatedStringHandler)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-iformatprovider-system-text-stringbuilder-appendinterpolatedstringhandler@))
370+
* `StringBuilder AppendJoin<T>(StringBuilder, char, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-string-system-collections-generic-ienumerable((-0))))
371+
* `StringBuilder AppendJoin<T>(StringBuilder, string, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-char-system-collections-generic-ienumerable((-0))))
370372
* `StringBuilder AppendJoin(StringBuilder, string, string[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-string-system-string()))
371373
* `StringBuilder AppendJoin(StringBuilder, string, Object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-string-system-object()))
372374
* `StringBuilder AppendJoin(StringBuilder, char, string[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-char-system-string()))

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The package targets `netstandard2.0` and is designed to support the following ru
1212
* `net5.0`, `net6.0`, `net7.0`, `net8.0`, `net9.0`, `net10.0`
1313

1414

15-
**API count: 522**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
15+
**API count: 524**<!-- singleLineInclude: apiCount. path: /apiCount.include.md -->
1616

1717

1818
**See [Milestones](../../milestones?state=closed) for release notes.**
@@ -841,6 +841,8 @@ The class `Polyfill` includes the following extension methods:
841841
* `StringBuilder Append(StringBuilder, 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@))
842842
* `StringBuilder Append(StringBuilder, StringBuilder.AppendInterpolatedStringHandler)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-appendinterpolatedstringhandler@))
843843
* `StringBuilder Append(StringBuilder, IFormatProvider?, StringBuilder.AppendInterpolatedStringHandler)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-iformatprovider-system-text-stringbuilder-appendinterpolatedstringhandler@))
844+
* `StringBuilder AppendJoin<T>(StringBuilder, char, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-string-system-collections-generic-ienumerable((-0))))
845+
* `StringBuilder AppendJoin<T>(StringBuilder, string, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-char-system-collections-generic-ienumerable((-0))))
844846
* `StringBuilder AppendJoin(StringBuilder, string, string[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-string-system-string()))
845847
* `StringBuilder AppendJoin(StringBuilder, string, Object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-string-system-object()))
846848
* `StringBuilder AppendJoin(StringBuilder, char, string[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-char-system-string()))

src/Polyfill/Polyfill_StringBuilder_AppendJoin.cs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,25 @@ namespace Polyfills;
99
static partial class Polyfill
1010
{
1111

12-
#if NETSTANDARD2_0|| NETFRAMEWORK
12+
#if NETSTANDARD2_0 || NETFRAMEWORK
13+
14+
/// <summary>Concatenates and appends the members of a collection, using the specified separator between each member.</summary>
15+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-string-system-collections-generic-ienumerable((-0)))
16+
public static StringBuilder AppendJoin<T>(
17+
this StringBuilder target,
18+
char separator,
19+
IEnumerable<T> values) =>
20+
target.Append(string.Join(separator.ToString(), values));
21+
22+
/// <summary>Concatenates and appends the members of a collection, using the specified char separator between each member.</summary>
23+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-char-system-collections-generic-ienumerable((-0)))
24+
public static StringBuilder AppendJoin<T>(
25+
this StringBuilder target,
26+
string separator,
27+
IEnumerable<T> values) =>
28+
target.Append(string.Join(separator, values));
1329

1430
/// <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>
15-
/// <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>
16-
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
17-
/// <returns>A reference to this instance after the append operation has completed.</returns>
1831
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-string-system-string())
1932
public static StringBuilder AppendJoin(
2033
this StringBuilder target,
@@ -23,9 +36,6 @@ public static StringBuilder AppendJoin(
2336
target.Append(string.Join(separator, values));
2437

2538
/// <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>
26-
/// <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>
27-
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
28-
/// <returns>A reference to this instance after the append operation has completed.</returns>
2939
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-string-system-object())
3040
public static StringBuilder AppendJoin(
3141
this StringBuilder target,
@@ -34,9 +44,6 @@ public static StringBuilder AppendJoin(
3444
target.Append(string.Join(separator, values));
3545

3646
/// <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>
37-
/// <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>
38-
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
39-
/// <returns>A reference to this instance after the append operation has completed.</returns>
4047
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-char-system-string())
4148
public static StringBuilder AppendJoin(
4249
this StringBuilder target,
@@ -45,9 +52,6 @@ public static StringBuilder AppendJoin(
4552
target.Append(string.Join(separator.ToString(), values));
4653

4754
/// <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>
48-
/// <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>
49-
/// <param name="values">An array that contains the strings to concatenate and append to the current instance of the string builder.</param>
50-
/// <returns>A reference to this instance after the append operation has completed.</returns>
5155
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin(system-char-system-object())
5256
public static StringBuilder AppendJoin(
5357
this StringBuilder target,
@@ -56,9 +60,6 @@ public static StringBuilder AppendJoin(
5660
target.Append(string.Join(separator.ToString(), values));
5761

5862
/// <summary>Concatenates and appends the members of a collection, using the specified char separator between each member.</summary>
59-
/// <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>
60-
/// <param name="values">A collection that contains the objects to concatenate and append to the current instance of the string builder.</param>
61-
/// <returns>A reference to this instance after the append operation has completed.</returns>
6263
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-char-system-collections-generic-ienumerable((-0)))
6364
public static StringBuilder AppendJoin<T>(
6465
this StringBuilder target,
@@ -67,9 +68,6 @@ public static StringBuilder AppendJoin<T>(
6768
target.Append(string.Join(separator.ToString(), values));
6869

6970
/// <summary>Concatenates and appends the members of a collection, using the specified char separator between each member.</summary>
70-
/// <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>
71-
/// <param name="values">A collection that contains the objects to concatenate and append to the current instance of the string builder.</param>
72-
/// <returns>A reference to this instance after the append operation has completed.</returns>
7371
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.appendjoin#system-text-stringbuilder-appendjoin-1(system-string-system-collections-generic-ienumerable((-0)))
7472
public static StringBuilder AppendJoin<T>(
7573
this StringBuilder target,

src/Tests/PolyfillTests_StringBuilder.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ public void AppendJoin()
106106
Assert();
107107
builder.AppendJoin(',', new object[]{"value1", "value2"});
108108
Assert();
109+
builder.AppendJoin(",", new object[]{"value1", "value2"}.Select(_=>_));
110+
Assert();
111+
builder.AppendJoin(',', new object[]{"value1", "value2"}.Select(_=>_));
112+
Assert();
109113
// ReSharper disable once RedundantExplicitParamsArrayCreation
110114
builder.AppendJoin<string>(',', ["value1", "value2"]);
111115
Assert();

0 commit comments

Comments
 (0)