Use new null checking syntax

This commit is contained in:
Matt Nadareski
2026-01-25 17:12:44 -05:00
parent 3c451b8570
commit 3211f1a218
6 changed files with 14 additions and 14 deletions

View File

@@ -83,7 +83,7 @@ namespace Hasher.Features
foreach (string typeString in types)
{
HashType? hashType = typeString.GetHashType();
if (hashType != null && !hashTypes.Contains(hashType.Value))
if (hashType is not null && !hashTypes.Contains(hashType.Value))
hashTypes.Add(item: hashType.Value);
}
}
@@ -141,7 +141,7 @@ namespace Hasher.Features
{
// Get all file hashes for flexibility
var hashes = HashTool.GetFileHashes(file);
if (hashes == null)
if (hashes is null)
{
if (debug) Console.WriteLine($"Hashes for {file} could not be retrieved");
return;
@@ -152,7 +152,7 @@ namespace Hasher.Features
foreach (HashType hashType in hashTypes)
{
// TODO: Make helper to pretty-print hash type names
if (hashes.TryGetValue(hashType, out string? hash) && hash != null)
if (hashes.TryGetValue(hashType, out string? hash) && hash is not null)
builder.AppendLine($"{hashType}: {hash}");
}

View File

@@ -15,7 +15,7 @@ namespace Hasher
var commandSet = CreateCommands(mainFeature);
// If we have no args, show the help and quit
if (args == null || args.Length == 0)
if (args is null || args.Length == 0)
{
commandSet.OutputAllHelp();
return;

View File

@@ -15,7 +15,7 @@ namespace SabreTools.Hashing
public static string? ByteArrayToString(byte[]? bytes)
{
// If we get null in, we send null out
if (bytes == null)
if (bytes is null)
return null;
try
@@ -38,7 +38,7 @@ namespace SabreTools.Hashing
public static ulong BytesToUInt64(byte[]? bytes)
{
// If we get null in, we send 0 out
if (bytes == null)
if (bytes is null)
return default;
ulong result = 0;

View File

@@ -31,7 +31,7 @@ namespace SabreTools.Hashing
// Get all file hashes
HashType[] standardHashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
var fileHashes = GetFileHashesAndSize(filename, standardHashTypes, out size);
if (fileHashes == null)
if (fileHashes is null)
return false;
// Assign the file hashes and return
@@ -58,7 +58,7 @@ namespace SabreTools.Hashing
// Get all file hashes
HashType[] standardHashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
var fileHashes = GetByteArrayHashesAndSize(array, standardHashTypes, out size);
if (fileHashes == null)
if (fileHashes is null)
return false;
// Assign the file hashes and return
@@ -85,7 +85,7 @@ namespace SabreTools.Hashing
// Get all file hashes
HashType[] standardHashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
var fileHashes = GetStreamHashesAndSize(stream, standardHashTypes, out size);
if (fileHashes == null)
if (fileHashes is null)
return false;
// Assign the file hashes and return
@@ -598,7 +598,7 @@ namespace SabreTools.Hashing
// Run the hashing
var hashers = GetStreamHashesInternal(input, hashTypes, leaveOpen, out size);
if (hashers == null)
if (hashers is null)
return null;
// Get the results
@@ -657,7 +657,7 @@ namespace SabreTools.Hashing
// Run the hashing
var hashers = GetStreamHashesInternal(input, hashTypes, leaveOpen, out size);
if (hashers == null)
if (hashers is null)
return null;
// Get the results

View File

@@ -358,7 +358,7 @@ namespace SabreTools.Hashing
private static string? GetCRCVariableLengthString(Crc cr)
{
// Ignore null values
if (cr.Hash == null)
if (cr.Hash is null)
return null;
// Get the total number of characters needed
@@ -375,7 +375,7 @@ namespace SabreTools.Hashing
private static string? GetSpamSumBase64String(SpamSum.SpamSum ss)
{
// Ignore null values
if (ss.Hash == null)
if (ss.Hash is null)
return null;
return System.Text.Encoding.ASCII.GetString(ss.Hash);

View File

@@ -54,7 +54,7 @@ namespace SabreTools.Hashing.SpamSum
protected override byte[] HashFinal()
{
string? digest = Finalize(0);
if (digest == null)
if (digest is null)
return [];
return Encoding.ASCII.GetBytes(digest.TrimEnd('\0'));