diff --git a/src/Zio.Tests/TestSearchPattern.cs b/src/Zio.Tests/TestSearchPattern.cs index 1d82170..f53ffc4 100644 --- a/src/Zio.Tests/TestSearchPattern.cs +++ b/src/Zio.Tests/TestSearchPattern.cs @@ -107,7 +107,7 @@ public void TestExtensions() var newPath = path.ChangeExtension(".zip"); Assert.Equal("/a/b/c/d.zip", newPath.FullName); Assert.Equal(new UPath("a/b/c/d.txt"), path.ToRelative()); - path.AssertNotNull(); + Assert.Equal(path, path.AssertAbsolute()); Assert.Throws(() => new UPath().AssertNotNull()); Assert.Throws(() => new UPath("not_absolute").AssertAbsolute()); } diff --git a/src/Zio/FileSystems/SubFileSystem.cs b/src/Zio/FileSystems/SubFileSystem.cs index a0b102e..c1a08f1 100644 --- a/src/Zio/FileSystems/SubFileSystem.cs +++ b/src/Zio/FileSystems/SubFileSystem.cs @@ -24,8 +24,7 @@ public class SubFileSystem : ComposeFileSystem /// If the directory subPath does not exist in the delegate FileSystem public SubFileSystem(IFileSystem fileSystem, UPath subPath, bool owned = true) : base(fileSystem, owned) { - subPath.AssertAbsolute(nameof(subPath)); - SubPath = subPath; + SubPath = subPath.AssertAbsolute(nameof(subPath)); if (!fileSystem.DirectoryExists(SubPath)) { throw NewDirectoryNotFoundException(SubPath); diff --git a/src/Zio/UPathExtensions.cs b/src/Zio/UPathExtensions.cs index cb40e26..ebffd8b 100644 --- a/src/Zio/UPathExtensions.cs +++ b/src/Zio/UPathExtensions.cs @@ -240,11 +240,13 @@ public static bool IsInDirectory(this UPath path, UPath directory, bool recursiv /// The path. /// The name of a parameter to include n the . /// If the path was null using the parameter name from - public static void AssertNotNull(this UPath path, string name = "path") + public static UPath AssertNotNull(this UPath path, string name = "path") { if (path.IsNull) Throw(name); + return path; + static void Throw(string name) => throw new ArgumentNullException(name); } @@ -254,11 +256,13 @@ public static void AssertNotNull(this UPath path, string name = "path") /// The path. /// The name of a parameter to include n the . /// If the path is not absolute using the parameter name from - public static void AssertAbsolute(this UPath path, string name = "path") + public static UPath AssertAbsolute(this UPath path, string name = "path") { if (!path.IsAbsolute) Throw(path, name); + return path; + static void Throw(UPath path, string name) => throw new ArgumentException($"Path `{path}` must be absolute", name); } }