Skip to content

Commit

Permalink
Prefer is null to == null
Browse files Browse the repository at this point in the history
ensures that an equals overload isn't use, and we don't compare structs
  • Loading branch information
iamcarbon authored and BobLd committed Mar 16, 2024
1 parent d19e6ad commit 95f0459
Show file tree
Hide file tree
Showing 97 changed files with 234 additions and 238 deletions.
4 changes: 2 additions & 2 deletions src/UglyToad.PdfPig/AcroForms/AcroFormFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ private AcroFieldBase GetAcroField(DictionaryToken fieldDictionary, Catalog cata
var fieldFlags = (uint) (fieldFlagsToken?.Long ?? 0);

AcroFieldBase result;
if (fieldType == null)
if (fieldType is null)
{
result = new AcroNonTerminalField(fieldDictionary, "Non-Terminal Field", fieldFlags, information, AcroFieldType.Unknown, children);
}
Expand Down Expand Up @@ -562,7 +562,7 @@ private static bool IsChoiceSelected(IReadOnlyList<string> selectedOptionNames,
continue;
}

if (selectedOptionIndices == null)
if (selectedOptionIndices is null)
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public override string ToString()
{
string AppendIfNotNull(string val, string label, string result)
{
if (val == null)
if (val is null)
{
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Annotations/AppearanceStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ internal AppearanceStream(IDictionary<string, StreamToken> appearanceStreamsBySt
/// <exception cref="ArgumentOutOfRangeException"></exception>
public StreamToken Get(string state)
{
if (appearanceStreamsByState == null)
if (appearanceStreamsByState is null)
{
throw new Exception("Cannot get appearance by state when this is a stateless appearance stream");
}
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Annotations/QuadPointsQuadrilateral.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class QuadPointsQuadrilateral
/// </summary>
public QuadPointsQuadrilateral(IReadOnlyList<PdfPoint> points)
{
if (points == null)
if (points is null)
{
throw new ArgumentNullException(nameof(points));
}
Expand Down
10 changes: 5 additions & 5 deletions src/UglyToad.PdfPig/Content/BasePageFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ protected BasePageFactory(
public TPage Create(int number, DictionaryToken dictionary, PageTreeMembers pageTreeMembers,
NamedDestinations namedDestinations)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
Expand Down Expand Up @@ -131,7 +131,7 @@ public TPage Create(int number, DictionaryToken dictionary, PageTreeMembers page

var contentStream = DirectObjectFinder.Get<StreamToken>(obj, PdfScanner);

if (contentStream == null)
if (contentStream is null)
{
throw new InvalidOperationException($"Could not find the contents for object {obj}.");
}
Expand All @@ -150,7 +150,7 @@ public TPage Create(int number, DictionaryToken dictionary, PageTreeMembers page
{
var contentStream = DirectObjectFinder.Get<StreamToken>(contents, PdfScanner);

if (contentStream == null)
if (contentStream is null)
{
throw new InvalidOperationException("Failed to parse the content for the page: " + number);
}
Expand Down Expand Up @@ -181,7 +181,7 @@ private TPage ProcessPageInternal(
{
IReadOnlyList<IGraphicsStateOperation> operations;

if (contentBytes == null || contentBytes.Count == 0)
if (contentBytes is null || contentBytes.Count == 0)
{
operations = Array.Empty<IGraphicsStateOperation>();
}
Expand Down Expand Up @@ -293,7 +293,7 @@ protected MediaBox GetMediaBox(int number, DictionaryToken dictionary, PageTreeM
{
mediaBox = pageTreeMembers.MediaBox;

if (mediaBox == null)
if (mediaBox is null)
{
ParsingOptions.Logger.Error(
$"The MediaBox was the wrong missing for page {number}. Using US Letter.");
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Content/DocumentInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public override string ToString()

private static void AppendPart(string name, string value, StringBuilder builder)
{
if (value == null)
if (value is null)
{
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Content/InlineImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ internal InlineImage(PdfRectangle bounds, int widthInSamples, int heightInSample
public bool TryGetBytes(out IReadOnlyList<byte> bytes)
{
bytes = null;
if (bytesFactory == null)
if (bytesFactory is null)
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Content/Page.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal Page(int number, DictionaryToken dictionary, MediaBox mediaBox, CropBox

private static string GetText(PageContent content)
{
if (content?.Letters == null)
if (content?.Letters is null)
{
return string.Empty;
}
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Content/PageTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class PageTreeNode
/// <summary>
/// Whether this node is the root node.
/// </summary>
public bool IsRoot => Parent == null;
public bool IsRoot => Parent is null;

/// <summary>
/// Create a new <see cref="PageTreeNode"/>.
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Content/Pages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ internal void AddPageFactory<TPage, TPageFactory>() where TPageFactory : IPageFa
typeof(ParsingOptions)
});

if (constructor == null)
if (constructor is null)
{
throw new InvalidOperationException($"Could not find valid constructor for page factory of type '{typeof(TPageFactory)}'. " +
"The page factory should have a constructor with the following parameters: " +
Expand Down
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig/Content/ResourceStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ private void LoadFontDictionary(DictionaryToken fontDictionary)

var fontObject = DirectObjectFinder.Get<DictionaryToken>(objectKey, scanner);

if (fontObject == null)
if (fontObject is null)
{
//This is a valid use case
continue;
Expand Down Expand Up @@ -269,7 +269,7 @@ public bool TryGetNamedColorSpace(NameToken name, out ResourceColorSpace namedTo
{
namedToken = default(ResourceColorSpace);

if (name == null)
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
Expand All @@ -286,7 +286,7 @@ public bool TryGetNamedColorSpace(NameToken name, out ResourceColorSpace namedTo

public ColorSpaceDetails GetColorSpaceDetails(NameToken name, DictionaryToken dictionary)
{
if (dictionary == null)
if (dictionary is null)
{
dictionary = new DictionaryToken(new Dictionary<NameToken, IToken>());
}
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Content/Word.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Word
/// <param name="letters">The letters contained in the word, in the correct order.</param>
public Word(IReadOnlyList<Letter> letters)
{
if (letters == null)
if (letters is null)
{
throw new ArgumentNullException(nameof(letters));
}
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/CrossReference/CrossReferenceTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal CrossReferenceTable(CrossReferenceType type, IReadOnlyDictionary<Indire
TrailerDictionary trailer,
IReadOnlyList<CrossReferenceOffset> crossReferenceOffsets)
{
if (objectOffsets == null)
if (objectOffsets is null)
{
throw new ArgumentNullException(nameof(objectOffsets));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class CrossReferenceTableBuilder

public void Add(CrossReferenceTablePart part)
{
if (part == null)
if (part is null)
{
throw new ArgumentNullException(nameof(part));
}
Expand All @@ -38,7 +38,7 @@ public CrossReferenceTable Build(long firstCrossReferenceOffset, long offsetCorr

var currentPart = parts.FirstOrDefault(x => x.Offset == firstCrossReferenceOffset);

if (currentPart == null)
if (currentPart is null)
{
// no XRef at given position
log.Warn($"Did not find an XRef object at the specified startxref position {firstCrossReferenceOffset}");
Expand Down Expand Up @@ -73,7 +73,7 @@ public CrossReferenceTable Build(long firstCrossReferenceOffset, long offsetCorr
}

currentPart = parts.FirstOrDefault(x => x.Offset == prevBytePos || x.Offset == prevBytePos + offsetCorrection);
if (currentPart == null)
if (currentPart is null)
{
log.Warn("Did not found XRef object pointed to by 'Prev' key at position " + prevBytePos);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/CrossReference/TrailerDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class TrailerDictionary
/// <param name="dictionary">The parsed dictionary from the document.</param>
internal TrailerDictionary(DictionaryToken dictionary)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}
Expand Down
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig/Encryption/CryptHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ internal class CryptHandler
public CryptHandler(DictionaryToken cryptDictionary,
NameToken streamName, NameToken stringName)
{
if (streamName == null)
if (streamName is null)
{
throw new ArgumentNullException(nameof(streamName));
}

if (stringName == null)
if (stringName is null)
{
throw new ArgumentNullException(nameof(stringName));
}
Expand All @@ -32,7 +32,7 @@ public CryptHandler(DictionaryToken cryptDictionary,

public CryptDictionary GetNamedCryptDictionary(NameToken name)
{
if (name == null)
if (name is null)
{
throw new ArgumentNullException(nameof(name));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ internal static class EncryptionDictionaryFactory
{
public static EncryptionDictionary Read(DictionaryToken encryptionDictionary, IPdfTokenScanner tokenScanner)
{
if (encryptionDictionary == null)
if (encryptionDictionary is null)
{
throw new ArgumentNullException(nameof(encryptionDictionary));
}
Expand Down
8 changes: 4 additions & 4 deletions src/UglyToad.PdfPig/Encryption/EncryptionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public EncryptionHandler(EncryptionDictionary encryptionDictionary, TrailerDicti
documentIdBytes = [];
}

if (encryptionDictionary == null)
if (encryptionDictionary is null)
{
return;
}
Expand Down Expand Up @@ -329,7 +329,7 @@ private static bool IsOwnerPasswordRevision5And6(byte[] passwordBytes, Encryptio

public IToken Decrypt(IndirectReference reference, IToken token)
{
if (token == null)
if (token is null)
{
throw new ArgumentNullException(nameof(token));
}
Expand Down Expand Up @@ -728,7 +728,7 @@ private static void UpdateMd5(MD5 md5, byte[] data)

private static byte[] GetPaddedPassword(byte[] password)
{
if (password == null || password.Length == 0)
if (password is null || password.Length == 0)
{
return PaddingBytes;
}
Expand Down Expand Up @@ -771,7 +771,7 @@ private static byte[] TruncatePasswordTo127Bytes(byte[] password)
private static byte[] ComputeStupidIsoHash(byte[] password, byte[] salt, byte[] vector)
{
// There are some details here https://web.archive.org/web/20180311160224/esec-lab.sogeti.com/posts/2011/09/14/the-undocumented-password-validation-algorithm-of-adobe-reader-x.html
if (vector == null)
if (vector is null)
{
vector = [];
}
Expand Down
10 changes: 5 additions & 5 deletions src/UglyToad.PdfPig/Filters/CcittFaxDecoderStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void Decode2D()
{
node = node.Walk(ReadBit());

if (node == null)
if (node is null)
{
goto mode;
}
Expand Down Expand Up @@ -224,7 +224,7 @@ private void DecodeRowType4()
{
node = node.Walk(ReadBit());

if (node == null)
if (node is null)
{
goto eof;
}
Expand Down Expand Up @@ -347,7 +347,7 @@ private int DecodeRun(Tree tree)
var bit = ReadBit();
node = node.Walk(bit);

if (node == null)
if (node is null)
{
throw new InvalidOperationException("Unknown code in Huffman RLE stream");
}
Expand Down Expand Up @@ -495,7 +495,7 @@ public void Fill(int depth, int path, int value)
var isSet = ((path >> bitPos) & 1) == 1;
var next = current.Walk(isSet);

if (next == null)
if (next is null)
{
next = new Node();

Expand Down Expand Up @@ -531,7 +531,7 @@ public void Fill(int depth, int path, Node node)
var isSet = ((path >> bitPos) & 1) == 1;
var next = current.Walk(isSet);

if (next == null)
if (next is null)
{
if (i == depth - 1)
{
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Filters/DecodeParameterResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal static class DecodeParameterResolver
{
public static DictionaryToken GetFilterParameters(DictionaryToken streamDictionary, int index)
{
if (streamDictionary == null)
if (streamDictionary is null)
{
throw new ArgumentNullException(nameof(streamDictionary));
}
Expand Down
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig/Filters/DefaultFilterProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ private DefaultFilterProvider()
/// <inheritdoc />
public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}

var token = dictionary.GetObjectOrDefault(NameToken.Filter, NameToken.F);
if (token == null)
if (token is null)
{
return Array.Empty<IFilter>();
}
Expand All @@ -89,7 +89,7 @@ public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary)
/// <inheritdoc />
public IReadOnlyList<IFilter> GetNamedFilters(IReadOnlyList<NameToken> names)
{
if (names == null)
if (names is null)
{
throw new ArgumentNullException(nameof(names));
}
Expand Down
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig/Filters/FilterProviderWithLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public IReadOnlyList<IFilter> GetAllFilters()

public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary, IPdfTokenScanner scanner)
{
if (dictionary == null)
if (dictionary is null)
{
throw new ArgumentNullException(nameof(dictionary));
}

var token = dictionary.GetObjectOrDefault(NameToken.Filter, NameToken.F);
if (token == null)
if (token is null)
{
return Array.Empty<IFilter>();
}
Expand All @@ -57,7 +57,7 @@ public IReadOnlyList<IFilter> GetFilters(DictionaryToken dictionary, IPdfTokenSc
case IndirectReferenceToken irt:
if (DirectObjectFinder.TryGet<NameToken>(irt, scanner, out var indirectName))
{
return GetNamedFilters(new []{ indirectName });
return GetNamedFilters(new[] { indirectName });
}
else if (DirectObjectFinder.TryGet<ArrayToken>(irt, scanner, out var indirectArray))
{
Expand Down
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Filters/FlateFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ internal class FlateFilter : IFilter
/// <inheritdoc />
public byte[] Decode(IReadOnlyList<byte> input, DictionaryToken streamDictionary, int filterIndex)
{
if (input == null)
if (input is null)
{
throw new ArgumentNullException(nameof(input));
}
Expand Down
Loading

0 comments on commit 95f0459

Please sign in to comment.