Skip to content

Commit 3211f1a

Browse files
committed
Use new null checking syntax
1 parent 3c451b8 commit 3211f1a

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

Hasher/Features/MainFeature.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static List<HashType> GetHashTypes(List<string> types)
8383
foreach (string typeString in types)
8484
{
8585
HashType? hashType = typeString.GetHashType();
86-
if (hashType != null && !hashTypes.Contains(hashType.Value))
86+
if (hashType is not null && !hashTypes.Contains(hashType.Value))
8787
hashTypes.Add(item: hashType.Value);
8888
}
8989
}
@@ -141,7 +141,7 @@ private static void PrintFileHashes(string file, List<HashType> hashTypes, bool
141141
{
142142
// Get all file hashes for flexibility
143143
var hashes = HashTool.GetFileHashes(file);
144-
if (hashes == null)
144+
if (hashes is null)
145145
{
146146
if (debug) Console.WriteLine($"Hashes for {file} could not be retrieved");
147147
return;
@@ -152,7 +152,7 @@ private static void PrintFileHashes(string file, List<HashType> hashTypes, bool
152152
foreach (HashType hashType in hashTypes)
153153
{
154154
// TODO: Make helper to pretty-print hash type names
155-
if (hashes.TryGetValue(hashType, out string? hash) && hash != null)
155+
if (hashes.TryGetValue(hashType, out string? hash) && hash is not null)
156156
builder.AppendLine($"{hashType}: {hash}");
157157
}
158158

Hasher/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void Main(string[] args)
1515
var commandSet = CreateCommands(mainFeature);
1616

1717
// If we have no args, show the help and quit
18-
if (args == null || args.Length == 0)
18+
if (args is null || args.Length == 0)
1919
{
2020
commandSet.OutputAllHelp();
2121
return;

SabreTools.Hashing/HashOperations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal static class HashOperations
1515
public static string? ByteArrayToString(byte[]? bytes)
1616
{
1717
// If we get null in, we send null out
18-
if (bytes == null)
18+
if (bytes is null)
1919
return null;
2020

2121
try
@@ -38,7 +38,7 @@ internal static class HashOperations
3838
public static ulong BytesToUInt64(byte[]? bytes)
3939
{
4040
// If we get null in, we send 0 out
41-
if (bytes == null)
41+
if (bytes is null)
4242
return default;
4343

4444
ulong result = 0;

SabreTools.Hashing/HashTool.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static bool GetStandardHashes(string filename, out long size, out string?
3131
// Get all file hashes
3232
HashType[] standardHashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
3333
var fileHashes = GetFileHashesAndSize(filename, standardHashTypes, out size);
34-
if (fileHashes == null)
34+
if (fileHashes is null)
3535
return false;
3636

3737
// Assign the file hashes and return
@@ -58,7 +58,7 @@ public static bool GetStandardHashes(byte[] array, out long size, out string? cr
5858
// Get all file hashes
5959
HashType[] standardHashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
6060
var fileHashes = GetByteArrayHashesAndSize(array, standardHashTypes, out size);
61-
if (fileHashes == null)
61+
if (fileHashes is null)
6262
return false;
6363

6464
// Assign the file hashes and return
@@ -85,7 +85,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
8585
// Get all file hashes
8686
HashType[] standardHashTypes = [HashType.CRC32, HashType.MD5, HashType.SHA1];
8787
var fileHashes = GetStreamHashesAndSize(stream, standardHashTypes, out size);
88-
if (fileHashes == null)
88+
if (fileHashes is null)
8989
return false;
9090

9191
// Assign the file hashes and return
@@ -598,7 +598,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
598598

599599
// Run the hashing
600600
var hashers = GetStreamHashesInternal(input, hashTypes, leaveOpen, out size);
601-
if (hashers == null)
601+
if (hashers is null)
602602
return null;
603603

604604
// Get the results
@@ -657,7 +657,7 @@ public static bool GetStandardHashes(Stream stream, out long size, out string? c
657657

658658
// Run the hashing
659659
var hashers = GetStreamHashesInternal(input, hashTypes, leaveOpen, out size);
660-
if (hashers == null)
660+
if (hashers is null)
661661
return null;
662662

663663
// Get the results

SabreTools.Hashing/HashWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public void Terminate()
358358
private static string? GetCRCVariableLengthString(Crc cr)
359359
{
360360
// Ignore null values
361-
if (cr.Hash == null)
361+
if (cr.Hash is null)
362362
return null;
363363

364364
// Get the total number of characters needed
@@ -375,7 +375,7 @@ public void Terminate()
375375
private static string? GetSpamSumBase64String(SpamSum.SpamSum ss)
376376
{
377377
// Ignore null values
378-
if (ss.Hash == null)
378+
if (ss.Hash is null)
379379
return null;
380380

381381
return System.Text.Encoding.ASCII.GetString(ss.Hash);

SabreTools.Hashing/SpamSum/SpamSum.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected override void HashCore(byte[] array, int ibStart, int cbSize)
5454
protected override byte[] HashFinal()
5555
{
5656
string? digest = Finalize(0);
57-
if (digest == null)
57+
if (digest is null)
5858
return [];
5959

6060
return Encoding.ASCII.GetBytes(digest.TrimEnd('\0'));

0 commit comments

Comments
 (0)