Use pattern matching to test for non-empty collections

This commit is contained in:
Jason Nelson
2021-03-10 09:39:12 -08:00
parent dc4968d5ab
commit 1cc8a40473
5 changed files with 7 additions and 7 deletions

View File

@@ -214,7 +214,7 @@ namespace Markdig.Extensions.Tables
}
}
if (currentRow != null && currentRow.Count > 0)
if (currentRow is { Count: > 0 })
{
gridTable.Add(currentRow);
}

View File

@@ -588,7 +588,7 @@ namespace Markdig.Parsers
}
if (TrackTrivia)
{
if (LinesBefore != null && LinesBefore.Count > 0)
if (LinesBefore is { Count: > 0 })
{
// single emptylines are significant for the syntax tree, attach
// them to the block

View File

@@ -36,7 +36,7 @@ namespace Markdig.Parsers
parser.Initialize();
parser.Index = i;
if (parser.OpeningCharacters != null && parser.OpeningCharacters.Length != 0)
if (parser.OpeningCharacters is { Length: > 0 })
{
foreach (var openingChar in parser.OpeningCharacters)
{

View File

@@ -363,7 +363,7 @@ namespace Markdig.Renderers
Write(" id=\"").WriteEscape(attributes.Id).Write("\"");
}
if (attributes.Classes != null && attributes.Classes.Count > 0)
if (attributes.Classes is { Count: > 0 })
{
Write(" class=\"");
for (int i = 0; i < attributes.Classes.Count; i++)
@@ -378,7 +378,7 @@ namespace Markdig.Renderers
Write("\"");
}
if (attributes.Properties != null && attributes.Properties.Count > 0)
if (attributes.Properties is { Count: > 0 })
{
foreach (var property in attributes.Properties)
{

View File

@@ -119,7 +119,7 @@ namespace Markdig.Syntax
/// </returns>
public static IEnumerable<T> Descendants<T>(this ContainerBlock block) where T : Block
{
if (block != null && block.Count > 0)
if (block is { Count: > 0 })
{
return BlockDescendantsInternal<T>(block);
}
@@ -133,7 +133,7 @@ namespace Markdig.Syntax
{
Debug.Assert(typeof(T).IsSubclassOf(typeof(Block)));
Stack<Block> stack = new Stack<Block>();
var stack = new Stack<Block>();
int childrenCount = block.Count;
while (childrenCount-- > 0)