Skip to content

Commit

Permalink
feat: add missing path APIs (#777)
Browse files Browse the repository at this point in the history
This adds support for all `System.IO.Path` members in .NET 5 and 6.

BREAKING CHANGE: This is a breaking change for people implementing `System.IO.Abstractions.IPath` or deriving from `System.IO.Abstractions.PathBase` because new members have been added to their API surface.

Fixes #774
  • Loading branch information
fgreinacher authored Dec 22, 2021
1 parent b802764 commit 5539592
Show file tree
Hide file tree
Showing 8 changed files with 224 additions and 50 deletions.
4 changes: 1 addition & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
<PackageReadmeFile>README.md</PackageReadmeFile>
<DefineConstants Condition="'$(TargetFramework)' != 'net461'">$(DefineConstants);FEATURE_FILE_SYSTEM_ACL_EXTENSIONS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0' OR '$(TargetFramework)' == 'netcoreapp3.1' OR '$(TargetFramework)' == 'netstandard2.1'">$(DefineConstants);FEATURE_ASYNC_FILE;FEATURE_ENUMERATION_OPTIONS;FEATURE_ADVANCED_PATH_OPERATIONS;FEATURE_PATH_JOIN_WITH_SPAN</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0'">$(DefineConstants);FEATURE_FILE_MOVE_WITH_OVERWRITE</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0'">$(DefineConstants);FEATURE_SUPPORTED_OS_ATTRIBUTE</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.0'">$(DefineConstants);FEATURE_FILE_SYSTEM_WATCHER_FILTERS</DefineConstants>
<DefineConstants Condition="'$(TargetFramework)' == 'net6.0' OR '$(TargetFramework)' == 'net5.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</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" Version="3.4.244">
Expand Down
59 changes: 59 additions & 0 deletions src/System.IO.Abstractions/IPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,64 @@ public interface IPath
/// <inheritdoc cref="System.IO.Path.TryJoin(ReadOnlySpan{char}, ReadOnlySpan{char}, ReadOnlySpan{char}, Span{char}, out int)"/>
bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, Span<char> destination, out int charsWritten);
#endif

#if FEATURE_ADVANCED_PATH_OPERATIONS
/// <inheritdoc cref="System.IO.Path.HasExtension(ReadOnlySpan{char})"/>
bool HasExtension(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.IsPathFullyQualified(ReadOnlySpan{char})"/>
bool IsPathFullyQualified(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.IsPathRooted(ReadOnlySpan{char})"/>
bool IsPathRooted(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.GetDirectoryName(ReadOnlySpan{char})"/>
ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.GetExtension(ReadOnlySpan{char})"/>
ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.GetFileName(ReadOnlySpan{char})"/>
ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.GetFileNameWithoutExtension(ReadOnlySpan{char})"/>
ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.GetPathRoot(ReadOnlySpan{char})"/>
ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path);

#endif

#if FEATURE_PATH_JOIN_WITH_PARAMS
/// <inheritdoc cref="System.IO.Path.Join(string,string)" />
string Join(string path1, string path2);

/// <inheritdoc cref="System.IO.Path.Join(string?, string?, string?)" />
string Join(string path1, string path2, string path3);

/// <inheritdoc cref="System.IO.Path.Join(string?[])" />
string Join(params string[] paths);
#endif

#if FEATURE_ENDS_IN_DIRECTORY_SEPARATOR
/// <inheritdoc cref="System.IO.Path.EndsInDirectorySeparator(ReadOnlySpan{char})"/>
bool EndsInDirectorySeparator(ReadOnlySpan<char> path);

/// <inheritdoc cref="System.IO.Path.EndsInDirectorySeparator(string)"/>
bool EndsInDirectorySeparator(string path);

/// <inheritdoc cref="System.IO.Path.TrimEndingDirectorySeparator(ReadOnlySpan{char})"/>
ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path);
/// <inheritdoc cref="System.IO.Path.TrimEndingDirectorySeparator(string)" />
string TrimEndingDirectorySeparator(string path);
#endif

#if FEATURE_PATH_JOIN_WITH_FOUR_PATHS
/// <inheritdoc cref="System.IO.Path.Join(ReadOnlySpan{char}, ReadOnlySpan{char}, ReadOnlySpan{char}, ReadOnlySpan{char})" />
string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, ReadOnlySpan<char> path4);

/// <inheritdoc cref="System.IO.Path.Join(string?, string?, string?, string?)" />
string Join(string path1, string path2, string path3, string path4);
#endif
}
}
51 changes: 51 additions & 0 deletions src/System.IO.Abstractions/PathBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,56 @@ internal PathBase() { }
/// <inheritdoc />
public abstract bool TryJoin(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, Span<char> destination, out int charsWritten);
#endif

#if FEATURE_ADVANCED_PATH_OPERATIONS
/// <inheritdoc />
public abstract bool HasExtension(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract bool IsPathFullyQualified(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract bool IsPathRooted(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path);

#endif
#if FEATURE_PATH_JOIN_WITH_PARAMS
/// <inheritdoc />
public abstract string Join(params string[] paths);

/// <inheritdoc />
public abstract string Join(string path1, string path2);
/// <inheritdoc />

public abstract string Join(string path1, string path2, string path3);

#endif

#if FEATURE_ENDS_IN_DIRECTORY_SEPARATOR
/// <inheritdoc />
public abstract bool EndsInDirectorySeparator(ReadOnlySpan<char> path);
/// <inheritdoc />
public abstract bool EndsInDirectorySeparator(string path);
/// <inheritdoc />
public abstract ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path);

/// <inheritdoc />
public abstract string TrimEndingDirectorySeparator(string path);
#endif

#if FEATURE_PATH_JOIN_WITH_FOUR_PATHS

/// <inheritdoc />
public abstract string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, ReadOnlySpan<char> path4);
/// <inheritdoc />
public abstract string Join(string path1, string path2, string path3, string path4);
#endif
}
}
110 changes: 110 additions & 0 deletions src/System.IO.Abstractions/PathWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,5 +187,115 @@ public override bool IsPathRooted(string path)
{
return Path.IsPathRooted(path);
}

#if FEATURE_ENDS_IN_DIRECTORY_SEPARATOR
/// <inheritdoc />
public override bool EndsInDirectorySeparator(ReadOnlySpan<char> path)
{
return Path.EndsInDirectorySeparator(path);
}

/// <inheritdoc />
public override bool EndsInDirectorySeparator(string path)
{
return Path.EndsInDirectorySeparator(path);
}

/// <inheritdoc />
public override ReadOnlySpan<char> TrimEndingDirectorySeparator(ReadOnlySpan<char> path)
{
return Path.TrimEndingDirectorySeparator(path);
}

/// <inheritdoc />
public override string TrimEndingDirectorySeparator(string path)
{
return Path.TrimEndingDirectorySeparator(path);
}
#endif

#if FEATURE_ADVANCED_PATH_OPERATIONS
/// <inheritdoc />
public override bool HasExtension(ReadOnlySpan<char> path)
{
return Path.HasExtension(path);
}

/// <inheritdoc />
public override bool IsPathFullyQualified(ReadOnlySpan<char> path)
{
return Path.IsPathFullyQualified(path);
}

/// <inheritdoc />
public override bool IsPathRooted(ReadOnlySpan<char> path)
{
return Path.IsPathRooted(path);
}

/// <inheritdoc />
public override ReadOnlySpan<char> GetDirectoryName(ReadOnlySpan<char> path)
{
return Path.GetDirectoryName(path);
}

/// <inheritdoc />
public override ReadOnlySpan<char> GetExtension(ReadOnlySpan<char> path)
{
return Path.GetExtension(path);
}

/// <inheritdoc />
public override ReadOnlySpan<char> GetFileName(ReadOnlySpan<char> path)
{
return Path.GetFileName(path);
}

/// <inheritdoc />
public override ReadOnlySpan<char> GetFileNameWithoutExtension(ReadOnlySpan<char> path)
{
return Path.GetFileNameWithoutExtension(path);
}

/// <inheritdoc />
public override ReadOnlySpan<char> GetPathRoot(ReadOnlySpan<char> path)
{
return Path.GetPathRoot(path);
}
#endif

#if FEATURE_PATH_JOIN_WITH_FOUR_PATHS
/// <inheritdoc />
public override string Join(string path1, string path2, string path3, string path4)
{
return Path.Join(path1, path2, path3, path4);
}

/// <inheritdoc />
public override string Join(ReadOnlySpan<char> path1, ReadOnlySpan<char> path2, ReadOnlySpan<char> path3, ReadOnlySpan<char> path4)
{
return Path.Join(path1, path2, path3, path4);
}
#endif

#if FEATURE_PATH_JOIN_WITH_PARAMS
/// <inheritdoc />
public override string Join(string path1, string path2)
{
return Path.Join(path1, path2);
}

/// <inheritdoc />
public override string Join(string path1, string path2, string path3)
{
return Path.Join(path1, path2, path3);
}

/// <inheritdoc />
public override string Join(params string[] paths)
{
return Path.Join(paths);
}
#endif
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,5 @@
"Char get_VolumeSeparatorChar()",
"Char[] get_InvalidPathChars()"
],
"MissingMembers": [
"Boolean EndsInDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"Boolean EndsInDirectorySeparator(System.String)",
"Boolean HasExtension(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathFullyQualified(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathRooted(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetDirectoryName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileNameWithoutExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetPathRoot(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] TrimEndingDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.String, System.String)",
"System.String Join(System.String, System.String, System.String)",
"System.String Join(System.String, System.String, System.String, System.String)",
"System.String Join(System.String[])",
"System.String TrimEndingDirectorySeparator(System.String)"
]
"MissingMembers": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,5 @@
"Char get_VolumeSeparatorChar()",
"Char[] get_InvalidPathChars()"
],
"MissingMembers": [
"Boolean EndsInDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"Boolean EndsInDirectorySeparator(System.String)",
"Boolean HasExtension(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathFullyQualified(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathRooted(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetDirectoryName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileNameWithoutExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetPathRoot(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] TrimEndingDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.String, System.String)",
"System.String Join(System.String, System.String, System.String)",
"System.String Join(System.String, System.String, System.String, System.String)",
"System.String Join(System.String[])",
"System.String TrimEndingDirectorySeparator(System.String)"
]
"MissingMembers": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
"MissingMembers": [
"Boolean EndsInDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"Boolean EndsInDirectorySeparator(System.String)",
"Boolean HasExtension(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathFullyQualified(System.ReadOnlySpan`1[System.Char])",
"Boolean IsPathRooted(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetDirectoryName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileName(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetFileNameWithoutExtension(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] GetPathRoot(System.ReadOnlySpan`1[System.Char])",
"System.ReadOnlySpan`1[System.Char] TrimEndingDirectorySeparator(System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char], System.ReadOnlySpan`1[System.Char])",
"System.String Join(System.String, System.String)",
Expand Down
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "14.0",
"version": "15.0",
"assemblyVersion": {
"precision": "major"
},
Expand Down

0 comments on commit 5539592

Please sign in to comment.