Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ private static bool GetLinqExpressionsBuiltWithIsInterpretingOnly()

public static bool IsInvokingStaticConstructorsSupported => !IsNativeAot;
public static bool IsInvokingFinalizersSupported => !IsNativeAot;
public static bool IsTypeEquivalenceSupported => !IsNativeAot && !IsMonoRuntime && IsWindows;

public static bool IsMetadataUpdateSupported => !IsNativeAot;

Expand Down
23 changes: 23 additions & 0 deletions src/libraries/System.Reflection/tests/GetTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,24 @@ public void GetType_InvalidAssemblyName()
Assert.Null(Type.GetType("ExtraComma, , System.Runtime"));
Assert.Throws<FileLoadException>(() => Type.GetType("System.Object, System.Runtime, Version=x.y"));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.IsTypeEquivalenceSupported))]
public void TestTypeIdentifierAttribute()
{
string typeName = $"{typeof(EquivalentValueType).FullName},{typeof(TestAssembly.ClassToInvoke).Assembly.GetName().Name}";
Type otherEquivalentValueType = Type.GetType(typeName);
Assert.True(otherEquivalentValueType.IsEquivalentTo(typeof(EquivalentValueType)));

var mi = typeof(MyNamespace1.ClassForTypeIdentifier).GetMethod("MyMethod");

// Sanity check.
object[] args = new object[1] { Activator.CreateInstance(typeof(EquivalentValueType)) };
Assert.Equal(42, mi.Invoke(null, args));

// Ensure we can invoke with an arg type that is duplicated in another assembly but having [TypeIdentifier].
args = new object[1] { Activator.CreateInstance(otherEquivalentValueType) };
Assert.Equal(42, mi.Invoke(null, args));
}
}

namespace MyNamespace1
Expand Down Expand Up @@ -323,6 +341,11 @@ namespace MyNamEspace3
{
public class Foo { }
}

public class ClassForTypeIdentifier
{
public static int MyMethod(EquivalentValueType v) => 42;
}
}

public class MyClass1 { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
<Compile Include="ExceptionTests.cs" />
<Compile Include="PointerTests.cs" />
<Compile Include="TypeTests.Constraints.cs" />
<Compile Include="TestAssembly\EquivalentValueType.cs"
Link="EquivalentValueType.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\EmbeddedImage.png">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.InteropServices;

[TypeIdentifier("MyScope", "MyTypeId")]
public struct EquivalentValueType
{
public int A;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="ClassToInvoke.cs" />
<Compile Include="EquivalentValueType.cs" />
<Compile Include="TestAssembly.cs" />
</ItemGroup>
</Project>
</Project>