Skip to content

Commit d2db41d

Browse files
authored
add string join overloads for ReadOnlySpan (#276)
1 parent e7c09ec commit d2db41d

File tree

4 files changed

+59
-4
lines changed

4 files changed

+59
-4
lines changed

apiCount.include.md

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

api_list.include.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,8 +577,12 @@
577577
#### StringPolyfill
578578

579579
* `string Join(char, object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-object()))
580+
* `string Join(char, ReadOnlySpan<object?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-readonlyspan((system-object))))
581+
* `string Join(char, ReadOnlySpan<string?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-readonlyspan((system-string))))
580582
* `string Join(char, string?[], int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()-system-int32-system-int32))
581583
* `string Join(char, string[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()))
584+
* `string Join(string, ReadOnlySpan<object?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-string-system-readonlyspan((system-object))))
585+
* `string Join(string, ReadOnlySpan<string?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-string-system-readonlyspan((system-string))))
582586
* `string Join<T>(char, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join-1(system-char-system-collections-generic-ienumerable((-0))))
583587

584588

readme.md

Lines changed: 5 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`
1313

1414

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

1717

1818
**See [Milestones](../../milestones?state=closed) for release notes.**
@@ -1046,8 +1046,12 @@ The class `Polyfill` includes the following extension methods:
10461046
#### StringPolyfill
10471047

10481048
* `string Join(char, object[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-object()))
1049+
* `string Join(char, ReadOnlySpan<object?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-readonlyspan((system-object))))
1050+
* `string Join(char, ReadOnlySpan<string?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-readonlyspan((system-string))))
10491051
* `string Join(char, string?[], int, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()-system-int32-system-int32))
10501052
* `string Join(char, string[])` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string()))
1053+
* `string Join(string, ReadOnlySpan<object?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-string-system-readonlyspan((system-object))))
1054+
* `string Join(string, ReadOnlySpan<string?>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-string-system-readonlyspan((system-string))))
10511055
* `string Join<T>(char, IEnumerable<T>)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join-1(system-char-system-collections-generic-ienumerable((-0))))
10521056

10531057

src/Polyfill/StringPolyfill.cs

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
namespace Polyfills;
55

6+
using System;
67
using System.Collections.Generic;
78
using System.Diagnostics;
89
using System.Diagnostics.CodeAnalysis;
@@ -18,7 +19,7 @@ static partial class StringPolyfill
1819
/// Concatenates an array of strings, using the specified separator between each member.
1920
/// </summary>
2021
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-string())
21-
public static string Join(char separator, string[] values) =>
22+
public static string Join(char separator, params string[] values) =>
2223
#if NETSTANDARD2_0 || NETFRAMEWORK
2324
string.Join(new([separator]), values);
2425
#else
@@ -29,13 +30,59 @@ public static string Join(char separator, string[] values) =>
2930
/// Concatenates the string representations of an array of objects, using the specified separator between each member.
3031
/// </summary>
3132
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-object())
32-
public static string Join(char separator, object[] values) =>
33+
public static string Join(char separator, params object[] values) =>
3334
#if NETSTANDARD2_0 || NETFRAMEWORK
3435
string.Join(new([separator]), values);
3536
#else
3637
string.Join(separator, values);
3738
#endif
3839

40+
#if FeatureMemory
41+
/// <summary>
42+
/// Concatenates the string representations of a span of objects, using the specified separator between each member.
43+
/// </summary>
44+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-readonlyspan((system-object)))
45+
public static string Join(char separator, scoped ReadOnlySpan<object?> values) =>
46+
#if NET9_0_OR_GREATER
47+
string.Join(separator, values);
48+
#else
49+
Join(separator, values.ToArray());
50+
#endif
51+
52+
/// <summary>
53+
/// Concatenates a span of strings, using the specified separator between each member.
54+
/// </summary>
55+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-char-system-readonlyspan((system-string)))
56+
public static string Join(char separator, scoped ReadOnlySpan<string?> values) =>
57+
#if NET9_0_OR_GREATER
58+
string.Join(separator, values);
59+
#else
60+
Join(separator, values.ToArray());
61+
#endif
62+
63+
/// <summary>
64+
/// Concatenates the string representations of a span of objects, using the specified separator between each member.
65+
/// </summary>
66+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-string-system-readonlyspan((system-object)))
67+
public static string Join(string separator, scoped ReadOnlySpan<object?> values) =>
68+
#if NET9_0_OR_GREATER
69+
string.Join(separator, values);
70+
#else
71+
string.Join(separator, values.ToArray());
72+
#endif
73+
74+
/// <summary>
75+
/// Concatenates a span of strings, using the specified separator between each member.
76+
/// </summary>
77+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.string.join#system-string-join(system-string-system-readonlyspan((system-string)))
78+
public static string Join(string separator, scoped ReadOnlySpan<string?> values) =>
79+
#if NET9_0_OR_GREATER
80+
string.Join(separator, values);
81+
#else
82+
string.Join(separator, values.ToArray());
83+
#endif
84+
#endif
85+
3986
/// <summary>
4087
/// Concatenates the specified elements of a string array, using the specified separator between each element.
4188
/// </summary>

0 commit comments

Comments
 (0)