Skip to content

Commit

Permalink
Merge pull request #690 from carbon/net46
Browse files Browse the repository at this point in the history
Bump  .NET framework target to net462
  • Loading branch information
xoofx committed Jan 14, 2023
2 parents 25323f0 + 641f3fe commit 78c4efb
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 71 deletions.
25 changes: 13 additions & 12 deletions src/Markdig.Tests/TestDescendantsOrder.cs
Expand Up @@ -2,6 +2,7 @@
using Markdig.Helpers;
using Markdig.Syntax;
using Markdig.Syntax.Inlines;
using System;
using System.Linq;
using System.Collections.Generic;

Expand Down Expand Up @@ -32,9 +33,9 @@ public static void TestSchemas(MarkdownDocument[] specsSyntaxTrees)

foreach (LiteralInline literalInline in syntaxTree.Descendants<LiteralInline>())
{
Assert.AreSame(ArrayHelper.Empty<ListBlock>(), literalInline.Descendants<ListBlock>());
Assert.AreSame(ArrayHelper.Empty<ParagraphBlock>(), literalInline.Descendants<ParagraphBlock>());
Assert.AreSame(ArrayHelper.Empty<ContainerInline>(), literalInline.Descendants<ContainerInline>());
Assert.AreSame(Array.Empty<ListBlock>(), literalInline.Descendants<ListBlock>());
Assert.AreSame(Array.Empty<ParagraphBlock>(), literalInline.Descendants<ParagraphBlock>());
Assert.AreSame(Array.Empty<ContainerInline>(), literalInline.Descendants<ContainerInline>());
}

foreach (ContainerInline containerInline in syntaxTree.Descendants<ContainerInline>())
Expand All @@ -49,13 +50,13 @@ public static void TestSchemas(MarkdownDocument[] specsSyntaxTrees)

if (containerInline.FirstChild is null)
{
Assert.AreSame(ArrayHelper.Empty<LiteralInline>(), containerInline.Descendants<LiteralInline>());
Assert.AreSame(ArrayHelper.Empty<LiteralInline>(), containerInline.FindDescendants<LiteralInline>());
Assert.AreSame(ArrayHelper.Empty<LiteralInline>(), (containerInline as MarkdownObject).Descendants<LiteralInline>());
Assert.AreSame(Array.Empty<LiteralInline>(), containerInline.Descendants<LiteralInline>());
Assert.AreSame(Array.Empty<LiteralInline>(), containerInline.FindDescendants<LiteralInline>());
Assert.AreSame(Array.Empty<LiteralInline>(), (containerInline as MarkdownObject).Descendants<LiteralInline>());
}

Assert.AreSame(ArrayHelper.Empty<ListBlock>(), containerInline.Descendants<ListBlock>());
Assert.AreSame(ArrayHelper.Empty<ParagraphBlock>(), containerInline.Descendants<ParagraphBlock>());
Assert.AreSame(Array.Empty<ListBlock>(), containerInline.Descendants<ListBlock>());
Assert.AreSame(Array.Empty<ParagraphBlock>(), containerInline.Descendants<ParagraphBlock>());
}

foreach (ParagraphBlock paragraphBlock in syntaxTree.Descendants<ParagraphBlock>())
Expand All @@ -64,7 +65,7 @@ public static void TestSchemas(MarkdownDocument[] specsSyntaxTrees)
(paragraphBlock as MarkdownObject).Descendants<LiteralInline>(),
paragraphBlock.Descendants<LiteralInline>());

Assert.AreSame(ArrayHelper.Empty<ParagraphBlock>(), paragraphBlock.Descendants<ParagraphBlock>());
Assert.AreSame(Array.Empty<ParagraphBlock>(), paragraphBlock.Descendants<ParagraphBlock>());
}

foreach (ContainerBlock containerBlock in syntaxTree.Descendants<ContainerBlock>())
Expand All @@ -79,9 +80,9 @@ public static void TestSchemas(MarkdownDocument[] specsSyntaxTrees)

if (containerBlock.Count == 0)
{
Assert.AreSame(ArrayHelper.Empty<LiteralInline>(), containerBlock.Descendants<LiteralInline>());
Assert.AreSame(ArrayHelper.Empty<LiteralInline>(), (containerBlock as Block).Descendants<LiteralInline>());
Assert.AreSame(ArrayHelper.Empty<LiteralInline>(), (containerBlock as MarkdownObject).Descendants<LiteralInline>());
Assert.AreSame(Array.Empty<LiteralInline>(), containerBlock.Descendants<LiteralInline>());
Assert.AreSame(Array.Empty<LiteralInline>(), (containerBlock as Block).Descendants<LiteralInline>());
Assert.AreSame(Array.Empty<LiteralInline>(), (containerBlock as MarkdownObject).Descendants<LiteralInline>());
}
}
}
Expand Down
26 changes: 0 additions & 26 deletions src/Markdig/Helpers/ArrayHelper.cs

This file was deleted.

36 changes: 15 additions & 21 deletions src/Markdig/Helpers/FastStringWriter.cs
Expand Up @@ -15,12 +15,6 @@ namespace Markdig.Helpers
{
internal sealed class FastStringWriter : TextWriter
{
#if NET452
private static Task CompletedTask => Task.FromResult(0);
#else
private static Task CompletedTask => Task.CompletedTask;
#endif

public override Encoding Encoding => Encoding.Unicode;

private char[] _chars;
Expand Down Expand Up @@ -66,13 +60,13 @@ public override void WriteLine(char value)
public override Task WriteAsync(char value)
{
Write(value);
return CompletedTask;
return Task.CompletedTask;
}

public override Task WriteLineAsync(char value)
{
WriteLine(value);
return CompletedTask;
return Task.CompletedTask;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -100,13 +94,13 @@ public override void WriteLine(string? value)
public override Task WriteAsync(string? value)
{
Write(value);
return CompletedTask;
return Task.CompletedTask;
}

public override Task WriteLineAsync(string? value)
{
WriteLine(value);
return CompletedTask;
return Task.CompletedTask;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -156,16 +150,16 @@ public override void WriteLine(char[] buffer, int index, int count)
public override Task WriteAsync(char[] buffer, int index, int count)
{
Write(buffer, index, count);
return CompletedTask;
return Task.CompletedTask;
}

public override Task WriteLineAsync(char[] buffer, int index, int count)
{
WriteLine(buffer, index, count);
return CompletedTask;
return Task.CompletedTask;
}

#if !(NET452 || NETSTANDARD2_0)
#if !(NETFRAMEWORK || NETSTANDARD2_0)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override void Write(ReadOnlySpan<char> value)
{
Expand All @@ -188,17 +182,17 @@ public override void WriteLine(ReadOnlySpan<char> buffer)
public override Task WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
{
Write(buffer.Span);
return CompletedTask;
return Task.CompletedTask;
}

public override Task WriteLineAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken = default)
{
WriteLine(buffer.Span);
return CompletedTask;
return Task.CompletedTask;
}
#endif

#if !(NET452 || NETSTANDARD2_0 || NETSTANDARD2_1)
#if !(NETFRAMEWORK || NETSTANDARD2_0 || NETSTANDARD2_1)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override void Write(StringBuilder? value)
{
Expand All @@ -225,13 +219,13 @@ public override void WriteLine(StringBuilder? value)
public override Task WriteAsync(StringBuilder? value, CancellationToken cancellationToken = default)
{
Write(value);
return CompletedTask;
return Task.CompletedTask;
}

public override Task WriteLineAsync(StringBuilder? value, CancellationToken cancellationToken = default)
{
WriteLine(value);
return CompletedTask;
return Task.CompletedTask;
}
#endif

Expand All @@ -247,7 +241,7 @@ public override void WriteLine()
public override Task WriteLineAsync()
{
WriteLine();
return CompletedTask;
return Task.CompletedTask;
}


Expand All @@ -273,9 +267,9 @@ private void Grow(int additionalCapacityBeyondPos)

public override void Close() { }

public override Task FlushAsync() => CompletedTask;
public override Task FlushAsync() => Task.CompletedTask;

#if !(NET452 || NETSTANDARD2_0)
#if !(NETFRAMEWORK || NETSTANDARD2_0)
public override ValueTask DisposeAsync() => default;
#endif

Expand Down
6 changes: 2 additions & 4 deletions src/Markdig/Markdig.targets
Expand Up @@ -5,9 +5,7 @@
<Copyright>Alexandre Mutel</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<Authors>Alexandre Mutel</Authors>
<!-- Markdig.Wpf still supports net452, a target still supported by by Microsoft until January 10, 2023 -->
<!-- see: https://github.com/xoofx/markdig/pull/466 -->
<TargetFrameworks>net452;netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
<TargetFrameworks>net462;netstandard2.0;netstandard2.1;net6.0</TargetFrameworks>
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<PackageTags>Markdown CommonMark md html md2html</PackageTags>
<PackageReleaseNotes>https://github.com/lunet-io/markdig/blob/master/changelog.md</PackageReleaseNotes>
Expand All @@ -26,7 +24,7 @@
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
</PropertyGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
<PackageReference Include="System.Memory" Version="4.5.4" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Polyfills/ConcurrentQueue.cs
Expand Up @@ -2,7 +2,7 @@
// This file is licensed under the BSD-Clause 2 license.
// See the license.txt file in the project root for more information.

#if NET452 || NETSTANDARD2_0
#if NETFRAMEWORK || NETSTANDARD2_0
namespace System.Collections.Concurrent
{
internal static class ConcurrentQueueExtensions
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Syntax/ContainerBlock.cs
Expand Up @@ -28,7 +28,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 = ArrayHelper.Empty<BlockWrapper>();
_children = Array.Empty<BlockWrapper>();
SetTypeKind(isInline: false, isContainer: true);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Syntax/Inlines/ContainerInline.cs
Expand Up @@ -109,7 +109,7 @@ public bool ContainsChild(Inline childToFind)
{
if (FirstChild is null)
{
return ArrayHelper.Empty<T>();
return Array.Empty<T>();
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Markdig/Syntax/LinkReferenceDefinitionGroup.cs
Expand Up @@ -16,7 +16,7 @@ namespace Markdig.Syntax
/// <seealso cref="ContainerBlock" />
public class LinkReferenceDefinitionGroup : ContainerBlock
{
#if NET452
#if NETFRAMEWORK
private static readonly StringComparer _unicodeIgnoreCaseComparer = StringComparer.InvariantCultureIgnoreCase;
#else
private static readonly StringComparer _unicodeIgnoreCaseComparer = CultureInfo.InvariantCulture.CompareInfo.GetStringComparer(CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace);
Expand Down
8 changes: 4 additions & 4 deletions src/Markdig/Syntax/MarkdownObjectExtensions.cs
Expand Up @@ -23,8 +23,8 @@ public static class MarkdownObjectExtensions
/// <returns>An iteration over the descendant elements</returns>
public static IEnumerable<MarkdownObject> Descendants(this MarkdownObject markdownObject)
{
Stack<MarkdownObject> stack = new Stack<MarkdownObject>();
Stack<bool> pushStack = new Stack<bool>();
var stack = new Stack<MarkdownObject>();
var pushStack = new Stack<bool>();

stack.Push(markdownObject);
pushStack.Push(false);
Expand Down Expand Up @@ -95,7 +95,7 @@ public static IEnumerable<MarkdownObject> Descendants(this MarkdownObject markdo
}
}

return ArrayHelper.Empty<T>();
return Array.Empty<T>();
}

/// <summary>
Expand Down Expand Up @@ -125,7 +125,7 @@ public static IEnumerable<MarkdownObject> Descendants(this MarkdownObject markdo
}
else
{
return ArrayHelper.Empty<T>();
return Array.Empty<T>();
}
}

Expand Down

0 comments on commit 78c4efb

Please sign in to comment.