diff --git a/src/Markdig.Tests/Markdig.Tests.csproj b/src/Markdig.Tests/Markdig.Tests.csproj index d5c885ce..13555a27 100644 --- a/src/Markdig.Tests/Markdig.Tests.csproj +++ b/src/Markdig.Tests/Markdig.Tests.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1;netcoreapp3.1 + net452;netcoreapp2.1;netcoreapp3.1 Library false diff --git a/src/Markdig.Tests/TestDescendantsOrder.cs b/src/Markdig.Tests/TestDescendantsOrder.cs index a56fd489..2d926e18 100644 --- a/src/Markdig.Tests/TestDescendantsOrder.cs +++ b/src/Markdig.Tests/TestDescendantsOrder.cs @@ -1,7 +1,7 @@ using NUnit.Framework; +using Markdig.Helpers; using Markdig.Syntax; using Markdig.Syntax.Inlines; -using System; using System.Linq; using System.Collections.Generic; @@ -33,9 +33,9 @@ namespace Markdig.Tests foreach (LiteralInline literalInline in syntaxTree.Descendants()) { - Assert.AreSame(Array.Empty(), literalInline.Descendants()); - Assert.AreSame(Array.Empty(), literalInline.Descendants()); - Assert.AreSame(Array.Empty(), literalInline.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), literalInline.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), literalInline.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), literalInline.Descendants()); } foreach (ContainerInline containerInline in syntaxTree.Descendants()) @@ -50,13 +50,13 @@ namespace Markdig.Tests if (containerInline.FirstChild is null) { - Assert.AreSame(Array.Empty(), containerInline.Descendants()); - Assert.AreSame(Array.Empty(), containerInline.FindDescendants()); - Assert.AreSame(Array.Empty(), (containerInline as MarkdownObject).Descendants()); + Assert.AreSame(ArrayHelper.Empty(), containerInline.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), containerInline.FindDescendants()); + Assert.AreSame(ArrayHelper.Empty(), (containerInline as MarkdownObject).Descendants()); } - Assert.AreSame(Array.Empty(), containerInline.Descendants()); - Assert.AreSame(Array.Empty(), containerInline.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), containerInline.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), containerInline.Descendants()); } foreach (ParagraphBlock paragraphBlock in syntaxTree.Descendants()) @@ -65,7 +65,7 @@ namespace Markdig.Tests (paragraphBlock as MarkdownObject).Descendants(), paragraphBlock.Descendants()); - Assert.AreSame(Array.Empty(), paragraphBlock.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), paragraphBlock.Descendants()); } foreach (ContainerBlock containerBlock in syntaxTree.Descendants()) @@ -80,9 +80,9 @@ namespace Markdig.Tests if (containerBlock.Count == 0) { - Assert.AreSame(Array.Empty(), containerBlock.Descendants()); - Assert.AreSame(Array.Empty(), (containerBlock as Block).Descendants()); - Assert.AreSame(Array.Empty(), (containerBlock as MarkdownObject).Descendants()); + Assert.AreSame(ArrayHelper.Empty(), containerBlock.Descendants()); + Assert.AreSame(ArrayHelper.Empty(), (containerBlock as Block).Descendants()); + Assert.AreSame(ArrayHelper.Empty(), (containerBlock as MarkdownObject).Descendants()); } } } diff --git a/src/Markdig/Helpers/ArrayHelper.cs b/src/Markdig/Helpers/ArrayHelper.cs new file mode 100644 index 00000000..b47f8bbc --- /dev/null +++ b/src/Markdig/Helpers/ArrayHelper.cs @@ -0,0 +1,25 @@ +// Copyright (c) Alexandre Mutel. All rights reserved. +// This file is licensed under the BSD-Clause 2 license. +// See the license.txt file in the project root for more information. +namespace Markdig.Helpers +{ + /// + /// Helper class for defining Empty arrays. + /// + public static class ArrayHelper + { + /// + /// An empty array. + /// +#if NET452 + public static T[] Empty() => EmptyArray.Value; + + private static class EmptyArray + { + public static readonly T[] Value = new T[0]; + } +#else + public static T[] Empty() => System.Array.Empty(); +#endif + } +} \ No newline at end of file diff --git a/src/Markdig/Markdig.targets b/src/Markdig/Markdig.targets index 6f2ce703..c99031c3 100644 --- a/src/Markdig/Markdig.targets +++ b/src/Markdig/Markdig.targets @@ -6,7 +6,7 @@ en-US 0.20.0 Alexandre Mutel - netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp3.1 + net452;netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp3.1 Markdown CommonMark md html md2html https://github.com/lunet-io/markdig/blob/master/changelog.md BSD-2-Clause @@ -20,6 +20,10 @@ snupkg + + + + diff --git a/src/Markdig/Syntax/ContainerBlock.cs b/src/Markdig/Syntax/ContainerBlock.cs index d7ffaf24..ec5b0aad 100644 --- a/src/Markdig/Syntax/ContainerBlock.cs +++ b/src/Markdig/Syntax/ContainerBlock.cs @@ -27,7 +27,7 @@ namespace Markdig.Syntax /// The parser used to create this block. protected ContainerBlock(BlockParser parser) : base(parser) { - children = Array.Empty(); + children = ArrayHelper.Empty(); } /// diff --git a/src/Markdig/Syntax/Inlines/ContainerInline.cs b/src/Markdig/Syntax/Inlines/ContainerInline.cs index 9278b723..04b4b1f6 100644 --- a/src/Markdig/Syntax/Inlines/ContainerInline.cs +++ b/src/Markdig/Syntax/Inlines/ContainerInline.cs @@ -99,7 +99,7 @@ namespace Markdig.Syntax.Inlines { if (FirstChild is null) { - return Array.Empty(); + return ArrayHelper.Empty(); } else { diff --git a/src/Markdig/Syntax/MarkdownObjectExtensions.cs b/src/Markdig/Syntax/MarkdownObjectExtensions.cs index 618dc924..8fa52fa9 100644 --- a/src/Markdig/Syntax/MarkdownObjectExtensions.cs +++ b/src/Markdig/Syntax/MarkdownObjectExtensions.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using Markdig.Helpers; using Markdig.Syntax.Inlines; namespace Markdig.Syntax @@ -94,7 +95,7 @@ namespace Markdig.Syntax } } - return Array.Empty(); + return ArrayHelper.Empty(); } /// @@ -124,7 +125,7 @@ namespace Markdig.Syntax } else { - return Array.Empty(); + return ArrayHelper.Empty(); } }