Use collection expressions

This commit is contained in:
Jason Nelson
2023-12-14 12:32:34 -08:00
parent f52ecee0b9
commit 342e264988
20 changed files with 26 additions and 29 deletions

View File

@@ -20,7 +20,7 @@ public class AbbreviationParser : BlockParser
/// </summary>
public AbbreviationParser()
{
OpeningCharacters = new[] { '*' };
OpeningCharacters = ['*'];
}
public override BlockState TryOpen(BlockProcessor processor)

View File

@@ -1786,6 +1786,6 @@ public class EmojiMapping
ThrowHelper.ArgumentException(string.Format("Smiley {0} is already present in the emoji mapping", smiley.Key));
}
OpeningCharacters = new List<char>(firstChars).ToArray();
OpeningCharacters = [.. firstChars];
}
}

View File

@@ -18,7 +18,7 @@ public class FigureBlockParser : BlockParser
/// </summary>
public FigureBlockParser()
{
OpeningCharacters = new[] { '^' };
OpeningCharacters = ['^'];
}
public override BlockState TryOpen(BlockProcessor processor)

View File

@@ -19,7 +19,7 @@ public class FooterBlockParser : BlockParser
/// </summary>
public FooterBlockParser()
{
OpeningCharacters = new[] {'^'};
OpeningCharacters = ['^'];
}
public override BlockState TryOpen(BlockProcessor processor)

View File

@@ -23,7 +23,7 @@ public class GenericAttributesParser : InlineParser
/// </summary>
public GenericAttributesParser()
{
OpeningCharacters = new[] { '{' };
OpeningCharacters = ['{'];
}
public override bool Match(InlineProcessor processor, ref StringSlice slice)
@@ -136,10 +136,7 @@ public class GenericAttributesParser : InlineParser
var text = slice.Text.Substring(start, end - start + 1);
if (isClass)
{
if (classes is null)
{
classes = new List<string>();
}
classes ??= new List<string>();
classes.Add(text);
}
else

View File

@@ -21,7 +21,7 @@ public class MathInlineParser : InlineParser
/// </summary>
public MathInlineParser()
{
OpeningCharacters = new[] { '$' };
OpeningCharacters = ['$'];
DefaultClass = "math";
}

View File

@@ -17,7 +17,7 @@ public class NoFollowLinksExtension : IMarkdownExtension
public NoFollowLinksExtension()
{
_referralLinksExtension = new ReferralLinksExtension(new[] { "nofollow" });
_referralLinksExtension = new ReferralLinksExtension(["nofollow"]);
}
public void Setup(MarkdownPipelineBuilder pipeline)

View File

@@ -12,7 +12,7 @@ public class GridTableParser : BlockParser
{
public GridTableParser()
{
OpeningCharacters = new[] { '+' };
OpeningCharacters = ['+'];
}
public override BlockState TryOpen(BlockProcessor processor)

View File

@@ -22,7 +22,7 @@ public class PipeTableBlockParser : BlockParser
/// </summary>
public PipeTableBlockParser()
{
OpeningCharacters = new[] {'-'};
OpeningCharacters = ['-'];
}
public override BlockState TryOpen(BlockProcessor processor)

View File

@@ -19,7 +19,7 @@ public class TaskListInlineParser : InlineParser
/// </summary>
public TaskListInlineParser()
{
OpeningCharacters = new[] {'['};
OpeningCharacters = ['['];
ListClass = "contains-task-list";
ListItemClass = "task-list-item";
}

View File

@@ -20,7 +20,7 @@ public class HeadingBlockParser : BlockParser, IAttributesParseable
/// </summary>
public HeadingBlockParser()
{
OpeningCharacters = new[] {'#'};
OpeningCharacters = ['#'];
}
/// <summary>

View File

@@ -18,7 +18,7 @@ public class HtmlBlockParser : BlockParser
/// </summary>
public HtmlBlockParser()
{
OpeningCharacters = new[] { '<' };
OpeningCharacters = ['<'];
}
public override BlockState TryOpen(BlockProcessor processor)

View File

@@ -20,7 +20,7 @@ namespace Markdig.Parsers.Inlines;
public class EmphasisInlineParser : InlineParser, IPostInlineProcessor
{
private CharacterMap<EmphasisDescriptor>? emphasisMap;
private readonly DelimitersObjectCache inlinesCache = new DelimitersObjectCache();
private readonly DelimitersObjectCache inlinesCache = new();
[Obsolete("Use TryCreateEmphasisInlineDelegate instead", error: false)]
public delegate EmphasisInline CreateEmphasisInlineDelegate(char emphasisChar, bool isStrong);
@@ -31,11 +31,11 @@ public class EmphasisInlineParser : InlineParser, IPostInlineProcessor
/// </summary>
public EmphasisInlineParser()
{
EmphasisDescriptors = new List<EmphasisDescriptor>()
{
EmphasisDescriptors =
[
new EmphasisDescriptor('*', 1, 2, true),
new EmphasisDescriptor('_', 1, 2, false)
};
];
}
/// <summary>
@@ -65,7 +65,7 @@ public class EmphasisInlineParser : InlineParser, IPostInlineProcessor
/// </summary>
[Obsolete("Use TryCreateEmphasisInlineList instead", error: false)]
public CreateEmphasisInlineDelegate? CreateEmphasisInline { get; set; }
public readonly List<TryCreateEmphasisInlineDelegate> TryCreateEmphasisInlineList = new List<TryCreateEmphasisInlineDelegate>();
public readonly List<TryCreateEmphasisInlineDelegate> TryCreateEmphasisInlineList = [];
public override void Initialize()
{

View File

@@ -15,7 +15,7 @@ public class EscapeInlineParser : InlineParser
{
public EscapeInlineParser()
{
OpeningCharacters = new[] {'\\'};
OpeningCharacters = ['\\'];
}
public override bool Match(InlineProcessor processor, ref StringSlice slice)

View File

@@ -21,7 +21,7 @@ public class HtmlEntityParser : InlineParser
/// </summary>
public HtmlEntityParser()
{
OpeningCharacters = new[] {'&'};
OpeningCharacters = ['&'];
}
public static bool TryParse(ref StringSlice slice, [NotNullWhen(true)] out string? literal, out int match)

View File

@@ -18,7 +18,7 @@ public class LineBreakInlineParser : InlineParser
/// </summary>
public LineBreakInlineParser()
{
OpeningCharacters = new[] { '\n', '\r' };
OpeningCharacters = ['\n', '\r'];
}
/// <summary>

View File

@@ -19,7 +19,7 @@ public class LinkInlineParser : InlineParser
/// </summary>
public LinkInlineParser()
{
OpeningCharacters = new[] {'[', ']', '!'};
OpeningCharacters = ['[', ']', '!'];
}
public override bool Match(InlineProcessor processor, ref StringSlice slice)
@@ -322,7 +322,7 @@ public class LinkInlineParser : InlineParser
if (label != null || LinkHelper.TryParseLabelTrivia(ref text, true, out label, out labelSpan))
{
SourceSpan labelWithTrivia = new SourceSpan(labelSpan.Start, labelSpan.End);
var labelWithTrivia = new SourceSpan(labelSpan.Start, labelSpan.End);
if (isLabelSpanLocal)
{
labelSpan = inlineState.GetSourcePositionFromLocalSpan(labelSpan);

View File

@@ -23,7 +23,7 @@ internal sealed class AllowNullAttribute : Attribute { }
#if !NET5_0_OR_GREATER
internal sealed class MemberNotNullAttribute : Attribute
{
public MemberNotNullAttribute(string member) => Members = new[] { member };
public MemberNotNullAttribute(string member) => Members = [member];
public MemberNotNullAttribute(params string[] members) => Members = members;

View File

@@ -21,7 +21,7 @@ public class CodeBlock : LeafBlock
}
private List<CodeBlockLine>? _codeBlockLines;
public List<CodeBlockLine> CodeBlockLines => _codeBlockLines ??= new();
public List<CodeBlockLine> CodeBlockLines => _codeBlockLines ??= [];
/// <summary>
/// Initializes a new instance of the <see cref="CodeBlock"/> class.

View File

@@ -27,7 +27,7 @@ public abstract class ContainerBlock : Block, IList<Block>, IReadOnlyList<Block>
/// <param name="parser">The parser used to create this block.</param>
protected ContainerBlock(BlockParser? parser) : base(parser)
{
_children = Array.Empty<BlockWrapper>();
_children = [];
SetTypeKind(isInline: false, isContainer: true);
}