-
Notifications
You must be signed in to change notification settings - Fork 5k
/
Copy pathAssemblyExtensionsTest.cs
32 lines (27 loc) · 1.1 KB
/
AssemblyExtensionsTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Xunit;
using System.Reflection.Metadata;
using System.Reflection;
namespace System.Runtime.Loader.Tests
{
public unsafe class AssemblyExtensionsTest
{
[Fact]
public void TryGetRawMetadata()
{
bool supportsRawMetadata = PlatformDetection.IsNotNativeAot;
Assembly assembly = typeof(AssemblyExtensionsTest).Assembly;
bool hasMetadata = assembly.TryGetRawMetadata(out byte* blob, out int length);
Assert.Equal(supportsRawMetadata, hasMetadata);
Assert.Equal(supportsRawMetadata, blob != null);
Assert.Equal(supportsRawMetadata, length > 0);
if (supportsRawMetadata)
{
var metadataReader = new MetadataReader(blob, length);
string assemblyName = metadataReader.GetString(metadataReader.GetAssemblyDefinition().Name);
Assert.Equal(assembly.GetName().Name, assemblyName);
}
}
}
}