From 9a1dc32a11a9c0a0d59d6ecbea197daef4635904 Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Thu, 9 Nov 2023 10:05:40 -0800 Subject: [PATCH] Improve nullability annotations --- src/Zio/FileSystemEntry.cs | 2 +- src/Zio/FileSystems/MemoryFileSystem.cs | 9 ++++----- src/Zio/FileSystems/MountFileSystem.cs | 6 +++--- src/Zio/UPath.cs | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Zio/FileSystemEntry.cs b/src/Zio/FileSystemEntry.cs index aaf38b9..495f7d6 100644 --- a/src/Zio/FileSystemEntry.cs +++ b/src/Zio/FileSystemEntry.cs @@ -121,7 +121,7 @@ public override string ToString() } /// - public bool Equals(FileSystemEntry other) + public bool Equals(FileSystemEntry? other) { if (other is null) return false; if (ReferenceEquals(this, other)) return true; diff --git a/src/Zio/FileSystems/MemoryFileSystem.cs b/src/Zio/FileSystems/MemoryFileSystem.cs index 563f9a4..c96c2e8 100644 --- a/src/Zio/FileSystems/MemoryFileSystem.cs +++ b/src/Zio/FileSystems/MemoryFileSystem.cs @@ -796,7 +796,7 @@ protected override IEnumerable EnumeratePathsImpl(UPath path, string sear // and the time we are going to actually visit it, it might have been // removed in the meantime, so we make sure here that we have a folder // and we don't throw an error if it is not - if (!(result.Node is DirectoryNode)) + if (result.Node is not DirectoryNode) { continue; } @@ -885,7 +885,7 @@ protected override IEnumerable EnumerateItemsImpl(UPath path, Se // and the time we are going to actually visit it, it might have been // removed in the meantime, so we make sure here that we have a folder // and we don't throw an error if it is not - if (!(result.Node is DirectoryNode)) + if (result.Node is not DirectoryNode) { continue; } @@ -1106,8 +1106,7 @@ void AssertNoDestination(FileSystemNode node) } } - - private void ValidateDirectory([NotNull] FileSystemNode? node, UPath srcPath) + private static void ValidateDirectory([NotNull] FileSystemNode? node, UPath srcPath) { if (node is FileNode) { @@ -1120,7 +1119,7 @@ private void ValidateDirectory([NotNull] FileSystemNode? node, UPath srcPath) } } - private void ValidateFile([NotNull] FileSystemNode? node, UPath srcPath) + private static void ValidateFile([NotNull] FileSystemNode? node, UPath srcPath) { if (node is null) { diff --git a/src/Zio/FileSystems/MountFileSystem.cs b/src/Zio/FileSystems/MountFileSystem.cs index 67924c0..2a666aa 100644 --- a/src/Zio/FileSystems/MountFileSystem.cs +++ b/src/Zio/FileSystems/MountFileSystem.cs @@ -33,7 +33,7 @@ public MountFileSystem(bool owned = true) : this(null, owned) /// Initializes a new instance of the class with a default backup filesystem. /// /// The default backup file system. - /// True if and mounted filesytems should be disposed when this instance is disposed. + /// True if and mounted filesystems should be disposed when this instance is disposed. public MountFileSystem(IFileSystem? defaultBackupFileSystem, bool owned = true) : base(defaultBackupFileSystem, owned) { _mounts = new SortedList(new UPathLengthComparer()); @@ -144,7 +144,7 @@ public IFileSystem Unmount(UPath name) { ValidateMountName(name); - IFileSystem mountFileSystem; + IFileSystem? mountFileSystem; if (!_mounts.TryGetValue(name, out mountFileSystem)) { @@ -1011,7 +1011,7 @@ private static UPath CombinePrefix(UPath prefix, UPath remaining) : prefix / remaining.ToRelative(); } - private void ValidateMountName(UPath name) + private static void ValidateMountName(UPath name) { name.AssertAbsolute(nameof(name)); if (name == UPath.Root) diff --git a/src/Zio/UPath.cs b/src/Zio/UPath.cs index 0d9a5d7..f80d9a5 100644 --- a/src/Zio/UPath.cs +++ b/src/Zio/UPath.cs @@ -194,7 +194,7 @@ public bool Equals(UPath other) } /// - public override bool Equals(object obj) + public override bool Equals(object? obj) { return obj is UPath path && Equals(path); }