Skip to content

Commit 7e07c8a

Browse files
authored
Append StringBuilder to StringBuilder (#280)
* Append StringBuilder * .
1 parent 7fc3f90 commit 7e07c8a

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

apiCount.include.md

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

api_list.include.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@
341341

342342
#### StringBuilder
343343

344+
* `StringBuilder Append(StringBuilder, StringBuilder?, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-system-int32-system-int32))
344345
* `StringBuilder Append(StringBuilder, ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-readonlyspan((system-char))))
345346
* `StringBuilder Append(StringBuilder, AppendInterpolatedStringHandler)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-appendinterpolatedstringhandler@))
346347
* `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@))

readme.md

Lines changed: 3 additions & 2 deletions
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`
1313

1414

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

1717

1818
**See [Milestones](../../milestones?state=closed) for release notes.**
@@ -65,7 +65,7 @@ This project uses features from the current stable SDK and C# language. As such
6565
```json
6666
{
6767
"sdk": {
68-
"version": "9.0.101",
68+
"version": "9.0.102",
6969
"allowPrerelease": true,
7070
"rollForward": "latestFeature"
7171
}
@@ -810,6 +810,7 @@ The class `Polyfill` includes the following extension methods:
810810

811811
#### StringBuilder
812812

813+
* `StringBuilder Append(StringBuilder, StringBuilder?, int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-system-int32-system-int32))
813814
* `StringBuilder Append(StringBuilder, ReadOnlySpan<char>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-readonlyspan((system-char))))
814815
* `StringBuilder Append(StringBuilder, AppendInterpolatedStringHandler)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-appendinterpolatedstringhandler@))
815816
* `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@))

src/Polyfill/Polyfill_StringBuilder_Append.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,38 @@ namespace Polyfills;
99

1010
static partial class Polyfill
1111
{
12+
#if !NETSTANDARD2_1_OR_GREATER && !NETCOREAPP2_1_OR_GREATER
13+
14+
/// <summary>
15+
/// Appends a copy of a substring within a specified string builder to this instance.
16+
/// </summary>
17+
/// <param name="value">The string builder that contains the substring to append.</param>
18+
/// <param name="startIndex">The starting position of the substring within value.</param>
19+
/// <param name="count">The number of characters in value to append.</param>
20+
/// <returns>A reference to this instance after the append operation is completed.</returns>
21+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder.append#system-text-stringbuilder-append(system-text-stringbuilder-system-int32-system-int32)
22+
public static StringBuilder Append(this StringBuilder target, StringBuilder? value, int startIndex, int count)
23+
{
24+
if (value == null)
25+
{
26+
if (startIndex == 0 && count == 0)
27+
{
28+
return target;
29+
}
30+
31+
throw new ArgumentNullException(nameof(value));
32+
}
33+
34+
if (count == 0)
35+
{
36+
return target;
37+
}
38+
39+
return target.Append(value.ToString(), startIndex, count);
40+
}
41+
42+
#endif
43+
1244
#if FeatureMemory && (!NETSTANDARD2_1_OR_GREATER && !NETCOREAPP2_1_OR_GREATER)
1345

1446
/// <summary>

0 commit comments

Comments
 (0)