mirror of
https://github.com/SabreTools/SabreTools.Hashing.git
synced 2026-02-04 05:36:04 +00:00
Use new null checking syntax
This commit is contained in:
@@ -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}");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'));
|
||||
|
||||
Reference in New Issue
Block a user