mirror of
https://github.com/xoofx/markdig.git
synced 2026-11-16 09:20:40 +00:00
Add Unsafe.As polyfill for NETSTANDARD 2.1
This commit is contained in:
@@ -604,12 +604,7 @@ namespace Markdig.Parsers
|
||||
|
||||
if (block.IsContainerBlock)
|
||||
{
|
||||
var currentContainer =
|
||||
#if NETSTANDARD2_1
|
||||
(ContainerBlock)block;
|
||||
#else
|
||||
Unsafe.As<ContainerBlock>(block);
|
||||
#endif
|
||||
var currentContainer = Unsafe.As<ContainerBlock>(block);
|
||||
CurrentContainer = currentContainer;
|
||||
LastBlock = currentContainer.LastChild;
|
||||
CurrentBlock = currentBlock;
|
||||
@@ -699,12 +694,7 @@ namespace Markdig.Parsers
|
||||
}
|
||||
}
|
||||
|
||||
#if NETSTANDARD2_1
|
||||
((LeafBlock)block)
|
||||
#else
|
||||
Unsafe.As<LeafBlock>(block)
|
||||
#endif
|
||||
.AppendLine(ref Line, Column, LineIndex, CurrentLineStartPosition, TrackTrivia);
|
||||
Unsafe.As<LeafBlock>(block).AppendLine(ref Line, Column, LineIndex, CurrentLineStartPosition, TrackTrivia);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -851,12 +841,7 @@ namespace Markdig.Parsers
|
||||
UnwindAllIndents();
|
||||
}
|
||||
|
||||
#if NETSTANDARD2_1
|
||||
((ParagraphBlock)currentBlock)
|
||||
#else
|
||||
Unsafe.As<ParagraphBlock>(currentBlock)
|
||||
#endif
|
||||
.AppendLine(ref Line, Column, LineIndex, CurrentLineStartPosition, TrackTrivia);
|
||||
Unsafe.As<ParagraphBlock>(currentBlock).AppendLine(ref Line, Column, LineIndex, CurrentLineStartPosition, TrackTrivia);
|
||||
}
|
||||
if (TrackTrivia)
|
||||
{
|
||||
@@ -926,12 +911,7 @@ namespace Markdig.Parsers
|
||||
}
|
||||
}
|
||||
|
||||
#if NETSTANDARD2_1
|
||||
((LeafBlock)block)
|
||||
#else
|
||||
Unsafe.As<LeafBlock>(block)
|
||||
#endif
|
||||
.AppendLine(ref Line, Column, LineIndex, CurrentLineStartPosition, TrackTrivia);
|
||||
Unsafe.As<LeafBlock>(block).AppendLine(ref Line, Column, LineIndex, CurrentLineStartPosition, TrackTrivia);
|
||||
}
|
||||
|
||||
if (newBlocks.Count > 0)
|
||||
|
||||
@@ -325,11 +325,7 @@ namespace Markdig.Parsers
|
||||
Inline? lastChild = container.LastChild;
|
||||
if (lastChild is not null && lastChild.IsContainerInline && !lastChild.IsClosed)
|
||||
{
|
||||
#if NETSTANDARD2_1
|
||||
container = ((ContainerInline)lastChild);
|
||||
#else
|
||||
container = Unsafe.As<ContainerInline>(lastChild);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -97,11 +97,7 @@ namespace Markdig.Parsers.Inlines
|
||||
return true;
|
||||
}
|
||||
|
||||
#if NETSTANDARD2_1
|
||||
ContainerInline container = (ContainerInline)root;
|
||||
#else
|
||||
ContainerInline container = Unsafe.As<ContainerInline>(root);
|
||||
#endif
|
||||
|
||||
List<EmphasisDelimiterInline>? delimiters = null;
|
||||
if (container is EmphasisDelimiterInline emphasisDelimiter)
|
||||
|
||||
@@ -152,12 +152,7 @@ namespace Markdig.Parsers
|
||||
var block = container[item.Index];
|
||||
if (block.IsLeafBlock)
|
||||
{
|
||||
#if NETSTANDARD2_1
|
||||
LeafBlock leafBlock = (LeafBlock)block;
|
||||
#else
|
||||
LeafBlock leafBlock = Unsafe.As<LeafBlock>(block);
|
||||
#endif
|
||||
|
||||
leafBlock.OnProcessInlinesBegin(inlineProcessor);
|
||||
if (leafBlock.ProcessInlines)
|
||||
{
|
||||
@@ -192,11 +187,7 @@ namespace Markdig.Parsers
|
||||
Array.Resize(ref blocks, blockCount * 2);
|
||||
ThrowHelper.CheckDepthLimit(blocks.Length);
|
||||
}
|
||||
#if NETSTANDARD2_1
|
||||
blocks[blockCount++] = new ContainerItem((ContainerBlock)block);
|
||||
#else
|
||||
blocks[blockCount++] = new ContainerItem(Unsafe.As<ContainerBlock>(block));
|
||||
#endif
|
||||
block.OnProcessInlinesBegin(inlineProcessor);
|
||||
goto process_new_block;
|
||||
}
|
||||
|
||||
17
src/Markdig/Polyfills/Unsafe.cs
Normal file
17
src/Markdig/Polyfills/Unsafe.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
// 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 System.Runtime.CompilerServices
|
||||
{
|
||||
#if NETSTANDARD2_1
|
||||
internal static class Unsafe
|
||||
{
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static T As<T>(object o) where T : class
|
||||
{
|
||||
return (T)o;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user