Skip to content

Commit 5d1885d

Browse files
authored
refactor: support new Path methods from .NET9 (#1192)
Add the two new methods to `Path` introduced in .NET 9: - `string Combine(params ReadOnlySpan<string> paths)` - `string Join(params ReadOnlySpan<string?> paths)`
1 parent 21fd787 commit 5d1885d

File tree

5 files changed

+38
-4
lines changed

5 files changed

+38
-4
lines changed

Directory.Build.props

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<DefineConstants Condition="'$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS;FEATURE_PATH_JOIN_WITH_SPAN;FEATURE_SPAN</DefineConstants>
1515
<DefineConstants Condition="'$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net7.0' OR '$(TargetFramework)' == 'net6.0'">$(DefineConstants);FEATURE_FILE_MOVE_WITH_OVERWRITE;FEATURE_SUPPORTED_OS_ATTRIBUTE;FEATURE_FILE_SYSTEM_WATCHER_FILTERS;FEATURE_ENDS_IN_DIRECTORY_SEPARATOR;FEATURE_PATH_JOIN_WITH_PARAMS;FEATURE_PATH_JOIN_WITH_FOUR_PATHS;FEATURE_FILE_SYSTEM_INFO_LINK_TARGET;FEATURE_CREATE_SYMBOLIC_LINK;FEATURE_FILESTREAM_OPTIONS</DefineConstants>
1616
<DefineConstants Condition="'$(TargetFramework)' == 'net9.0' OR '$(TargetFramework)' == 'net8.0' OR '$(TargetFramework)' == 'net7.0'">$(DefineConstants);FEATURE_PATH_EXISTS;FEATURE_FILE_SYSTEM_WATCHER_WAIT_WITH_TIMESPAN;FEATURE_FILE_ATTRIBUTES_VIA_HANDLE;FEATURE_CREATE_TEMP_SUBDIRECTORY;FEATURE_READ_LINES_ASYNC;FEATURE_UNIX_FILE_MODE</DefineConstants>
17+
<DefineConstants Condition="'$(TargetFramework)' == 'net9.0'">$(DefineConstants);FEATURE_PATH_SPAN</DefineConstants>
1718
<DefineConstants>$(DefineConstants);FEATURE_SERIALIZABLE</DefineConstants>
1819
</PropertyGroup>
1920
<ItemGroup>

src/TestableIO.System.IO.Abstractions.Wrappers/PathBase.cs

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ internal PathBase() { }
4343

4444
/// <inheritdoc cref="Path.Combine(string[])"/>
4545
public abstract string Combine(params string[] paths);
46+
47+
#if FEATURE_PATH_SPAN
48+
/// <inheritdoc cref="Path.Combine(ReadOnlySpan{string})"/>
49+
public abstract string Combine(params ReadOnlySpan<string> paths);
50+
#endif
4651

4752
/// <inheritdoc cref="Path.Combine(string,string)"/>
4853
public abstract string Combine(string path1, string path2);
@@ -117,6 +122,11 @@ internal PathBase() { }
117122
/// <inheritdoc />
118123
public abstract string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3);
119124

125+
#if FEATURE_PATH_SPAN
126+
/// <inheritdoc cref="Path.Join(ReadOnlySpan{string})"/>
127+
public abstract string Join(params ReadOnlySpan<string> paths);
128+
#endif
129+
120130
/// <inheritdoc />
121131
public abstract bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, Span<char> destination, out int charsWritten);
122132

src/TestableIO.System.IO.Abstractions.Wrappers/PathWrapper.cs

+16
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ public override string Combine(params string[] paths)
5656
return Path.Combine(paths);
5757
}
5858

59+
#if FEATURE_PATH_SPAN
60+
/// <inheritdoc />
61+
public override string Combine(params ReadOnlySpan<string> paths)
62+
{
63+
return Path.Combine(paths);
64+
}
65+
#endif
66+
5967
/// <inheritdoc />
6068
public override string Combine(string path1, string path2)
6169
{
@@ -185,6 +193,14 @@ public override string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2)
185193
public override string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3) =>
186194
Path.Join(path1, path2, path3);
187195

196+
#if FEATURE_PATH_SPAN
197+
/// <inheritdoc />
198+
public override string Join(params ReadOnlySpan<string> paths)
199+
{
200+
return Path.Join(paths);
201+
}
202+
#endif
203+
188204
/// <inheritdoc />
189205
public override bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, Span<char> destination, out int charsWritten) =>
190206
Path.TryJoin(path1, path2, destination, out charsWritten);

src/TestableIO.System.IO.Abstractions/IPath.cs

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public interface IPath : IFileSystemEntity
3333
/// <inheritdoc cref="Path.Combine(string[])" />
3434
string Combine(params string[] paths);
3535

36+
#if FEATURE_PATH_SPAN
37+
/// <inheritdoc cref="Path.Combine(ReadOnlySpan{string})" />
38+
string Combine(params ReadOnlySpan<string> paths);
39+
#endif
40+
3641
#if FEATURE_ENDS_IN_DIRECTORY_SEPARATOR
3742
/// <inheritdoc cref="Path.EndsInDirectorySeparator(ReadOnlySpan{char})" />
3843
bool EndsInDirectorySeparator(ReadOnlySpan<char> path);
@@ -148,6 +153,11 @@ string Join(ReadOnlySpan<char> path1,
148153
ReadOnlySpan<char> path2,
149154
ReadOnlySpan<char> path3);
150155

156+
#if FEATURE_PATH_SPAN
157+
/// <inheritdoc cref="Path.Join(ReadOnlySpan{string?})" />
158+
string Join(params ReadOnlySpan<string?> paths);
159+
#endif
160+
151161
/// <inheritdoc cref="Path.TryJoin(ReadOnlySpan{char}, ReadOnlySpan{char}, Span{char}, out int)" />
152162
bool TryJoin(ReadOnlySpan<char> path1,
153163
ReadOnlySpan<char> path2,

tests/TestableIO.System.IO.Abstractions.Wrappers.Tests/__snapshots__/ApiParityTests.Path_.NET 9.0.snap

+1-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,5 @@
66
"Char get_VolumeSeparatorChar()",
77
"Char[] get_InvalidPathChars()"
88
],
9-
"MissingMembers": [
10-
"System.String Combine(System.ReadOnlySpan`1[System.String])",
11-
"System.String Join(System.ReadOnlySpan`1[System.String])"
12-
]
9+
"MissingMembers": []
1310
}

0 commit comments

Comments
 (0)