Skip to content

Commit 2f6091a

Browse files
committed
Append StringBuilder
1 parent 7fc3f90 commit 2f6091a

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}

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)