未验证 提交 6154792f 编写于 作者: T Theodore Tsirpanis 提交者: GitHub

Use `Array.Empty()` in `System.Reflection.Metadata`. (#70862)

It is now available in all frameworks it targets.
上级 e3a20971
...@@ -109,7 +109,6 @@ System.Reflection.PortableExecutable.ManagedPEBuilder</PackageDescription> ...@@ -109,7 +109,6 @@ System.Reflection.PortableExecutable.ManagedPEBuilder</PackageDescription>
<Compile Include="System\Reflection\Internal\MemoryBlocks\StreamMemoryBlockProvider.cs" /> <Compile Include="System\Reflection\Internal\MemoryBlocks\StreamMemoryBlockProvider.cs" />
<Compile Include="System\Reflection\Internal\Utilities\BitArithmetic.cs" /> <Compile Include="System\Reflection\Internal\Utilities\BitArithmetic.cs" />
<Compile Include="System\Reflection\Internal\Utilities\StringUtils.cs" /> <Compile Include="System\Reflection\Internal\Utilities\StringUtils.cs" />
<Compile Include="System\Reflection\Internal\Utilities\EmptyArray.cs" />
<Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" /> <Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.cs" Condition="'$(TargetFrameworkIdentifier)' != '.NETCoreApp'" />
<Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" /> <Compile Include="System\Reflection\Internal\Utilities\EncodingHelper.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
<Compile Include="System\Reflection\Internal\Utilities\StreamExtensions.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" /> <Compile Include="System\Reflection\Internal\Utilities\StreamExtensions.netcoreapp.cs" Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp'" />
......
...@@ -16,7 +16,7 @@ public static byte[] ReadBytes(byte* buffer, int byteCount) ...@@ -16,7 +16,7 @@ public static byte[] ReadBytes(byte* buffer, int byteCount)
{ {
if (byteCount == 0) if (byteCount == 0)
{ {
return EmptyArray<byte>.Instance; return Array.Empty<byte>();
} }
byte[] result = new byte[byteCount]; byte[] result = new byte[byteCount];
......
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace System.Reflection.Internal
{
internal static class EmptyArray<T>
{
#pragma warning disable CA1825 // Array.Empty<T>() doesn't exist in all configurations
internal static readonly T[] Instance = new T[0];
#pragma warning restore CA1825
}
}
...@@ -98,7 +98,7 @@ internal byte[] GetBytes(BlobHandle handle) ...@@ -98,7 +98,7 @@ internal byte[] GetBytes(BlobHandle handle)
int numberOfBytes = Block.PeekCompressedInteger(offset, out bytesRead); int numberOfBytes = Block.PeekCompressedInteger(offset, out bytesRead);
if (numberOfBytes == BlobReader.InvalidCompressedInteger) if (numberOfBytes == BlobReader.InvalidCompressedInteger)
{ {
return EmptyArray<byte>.Instance; return Array.Empty<byte>();
} }
return Block.PeekBytes(offset + bytesRead, numberOfBytes); return Block.PeekBytes(offset + bytesRead, numberOfBytes);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册