Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit e474192

Browse files
authored
Fix failures in System.Reflection.TypeExtensions.CoreCLR (#19841)
1 parent 3882e3e commit e474192

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/System.Reflection.TypeExtensions/tests/CoreCLR/MemberInfoTests.CoreCLR.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public event EventHandler Event { add { } remove { } }
2727
new object[] { typeof(Test<>).GetGenericArguments()[0].GetTypeInfo(), 0x2A }
2828
};
2929

30-
[Theory]
30+
[ConditionalTheory(nameof(GetMetadataTokenSupported))]
3131
[MemberData(nameof(MembersWithExpectedTableIndex))]
3232
public void SuccessImpliesNonNilWithCorrectTable(MemberInfo member, int expectedTableIndex)
3333
{
@@ -37,7 +37,7 @@ public void SuccessImpliesNonNilWithCorrectTable(MemberInfo member, int expected
3737
Assert.NotEqual(0, TableIndex(token));
3838
}
3939

40-
[Fact]
40+
[ConditionalFact(nameof(GetMetadataTokenSupported), nameof(IsReflectionEmitSupported))]
4141
public static void UnbakedReflectionEmitType_HasNoMetadataToken()
4242
{
4343
AssemblyBuilder assembly = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("dynamic"), AssemblyBuilderAccess.Run);
@@ -48,6 +48,20 @@ public static void UnbakedReflectionEmitType_HasNoMetadataToken()
4848
Assert.Throws<InvalidOperationException>(() => method.GetMetadataToken());
4949
}
5050

51+
public static bool GetMetadataTokenSupported
52+
{
53+
get
54+
{
55+
if (!PlatformDetection.IsNetNative)
56+
return true;
57+
58+
// Expected false but in case .Net Native ever changes its mind...
59+
return typeof(MetadataTokenTests).HasMetadataToken();
60+
}
61+
}
62+
63+
public static bool IsReflectionEmitSupported => PlatformDetection.IsReflectionEmitSupported;
64+
5165
private static int TableIndex(int token) => token >> 24;
5266
private static int RowIndex(int token) => token & 0x00FFFFFF;
5367
}

src/System.Reflection.TypeExtensions/tests/CoreCLR/System.Reflection.TypeExtensions.CoreCLR.Tests.csproj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<ItemGroup>
1919
<Compile Include="MemberInfoTests.CoreCLR.cs" />
2020
<Compile Include="ModuleTests.CoreCLR.cs" />
21+
<Compile Include="$(CommonTestPath)\System\PlatformDetection.cs">
22+
<Link>Common\System\PlatformDetection.cs</Link>
23+
</Compile>
2124
</ItemGroup>
2225
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" />
23-
</Project>
26+
</Project>

0 commit comments

Comments
 (0)