_fields.Add(tb.DefineField("_methodInfos", typeof(MethodInfo[]), FieldAttributes.Private));
_methodInfos = new List<MethodInfo>();
+
+ _assembly.EnsureTypeIsVisible(proxyBaseType);
}
private void Complete()
}
[Fact]
+ [SkipOnMono("https://github.com/dotnet/runtime/issues/47989")]
+ public static void Create_Using_PrivateProxy()
+ {
+ Assert.NotNull(TestType_PrivateProxy.Proxy<TestType_IHelloService>());
+ }
+
+ [Fact]
+ [SkipOnMono("https://github.com/dotnet/runtime/issues/47989")]
+ public static void Create_Using_PrivateProxyAndInternalService()
+ {
+ Assert.NotNull(TestType_PrivateProxy.Proxy<TestType_InternalInterfaceService>());
+ }
+
+ [Fact]
+ [SkipOnMono("https://github.com/dotnet/runtime/issues/47989")]
+ public static void Create_Using_PrivateProxyAndInternalServiceWithExternalGenericArgument()
+ {
+ Assert.NotNull(TestType_PrivateProxy.Proxy<TestType_InternalInterfaceWithNonPublicExternalGenericArgument>());
+ }
+
+ [Fact]
+ [SkipOnMono("https://github.com/dotnet/runtime/issues/47989")]
+ public static void Create_Using_InternalProxy()
+ {
+ Assert.NotNull(DispatchProxy.Create<TestType_InternalInterfaceService, InternalInvokeProxy>());
+ }
+
+ [Fact]
+ public static void Create_Using_ExternalNonPublicService()
+ {
+ Assert.NotNull(DispatchProxy.Create<DispatchProxyTestDependency.TestType_IExternalNonPublicHiService, TestDispatchProxy>());
+ }
+
+ [Fact]
+ [SkipOnMono("https://github.com/dotnet/runtime/issues/47989")]
+ public static void Create_Using_InternalProxyWithExternalNonPublicBaseType()
+ {
+ Assert.NotNull(DispatchProxy.Create<TestType_IHelloService, TestType_InternalProxyInternalBaseType>());
+ }
+
+ [Fact]
+ public static void Create_Using_InternalServiceImplementingNonPublicExternalService()
+ {
+ Assert.NotNull(DispatchProxy.Create<TestType_InternalInterfaceImplementsNonPublicExternalType, TestDispatchProxy>());
+ }
+
+ [Fact]
+ public static void Create_Using_InternalServiceWithGenericArgumentBeingNonPublicExternalService()
+ {
+ Assert.NotNull(DispatchProxy.Create<TestType_InternalInterfaceWithNonPublicExternalGenericArgument, TestDispatchProxy>());
+ }
+
+ [Fact]
+ [SkipOnMono("https://github.com/dotnet/runtime/issues/47989")]
+ public static void Create_Using_InternalProxyWithBaseTypeImplementingServiceWithgenericArgumentBeingNonPublicExternalService()
+ {
+ Assert.NotNull(DispatchProxy.Create<TestType_IHelloService, TestType_InternalProxyImplementingInterfaceWithGenericArgumentBeingNonPublicExternalType>());
+ }
+
+ [Fact]
public static void Invoke_Receives_Correct_MethodInfo_And_Arguments()
{
bool wasInvoked = false;
<Project Sdk="Microsoft.NET.Sdk">
+
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
</PropertyGroup>
+
<ItemGroup>
<Compile Include="DispatchProxyTests.cs" />
<Compile Include="TestTypes.cs" />
</ItemGroup>
+
+ <ItemGroup>
+ <ProjectReference Include="TestDependency\System.Reflection.DispatchProxy.TestDependency.csproj" />
+ </ItemGroup>
+
</Project>
\ No newline at end of file
--- /dev/null
+// 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.CompilerServices;
+
+[assembly: InternalsVisibleTo("System.Reflection.DispatchProxy.Tests, PublicKey=00240000048000009400000006020000002400005253413100040000010001004b86c4cb78549b34bab61a3b1800e23bfeb5b3ec390074041536a7e3cbd97f5f04cf0f857155a8928eaa29ebfd11cfbbad3ba70efea7bda3226c6a8d370a4cd303f714486b6ebc225985a638471e6ef571cc92a4613c00b8fa65d61ccee0cbe5f36330c9a01f4183559f1bef24cc2917c6d913e3a541333a1d05d9bed22b38cb")]
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <Compile Include="InternalsVisibleTo.cs" />
+ <Compile Include="TestTypes.cs" />
+ </ItemGroup>
+
+</Project>
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.Reflection;
+
+namespace DispatchProxyTestDependency
+{
+ internal interface TestType_IExternalNonPublicHiService
+ {
+ string Hi(string message);
+ }
+
+ internal class TestType_ExternalNonPublicBaseClassForProxy : DispatchProxy
+ {
+ protected override object Invoke(MethodInfo targetMethod, object[] args) => null;
+ }
+}
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
+using DispatchProxyTestDependency;
// Test types used to make proxies.
string Echo2(string message);
}
+internal interface TestType_InternalInterfaceImplementsNonPublicExternalType : TestType_IExternalNonPublicHiService
+{
+ string Hi2(string message);
+}
+
+internal interface TestType_ServiceWithGenericArgument<T>
+{
+ T GetInnerService();
+}
+
+internal interface TestType_InternalInterfaceWithNonPublicExternalGenericArgument : TestType_ServiceWithGenericArgument<TestType_IExternalNonPublicHiService>
+{
+}
+
public interface TypeType_GenericMethod
{
T Echo<T>(T messages);
}
}
+public class TestType_PrivateProxy
+{
+ public static T Proxy<T>() => DispatchProxy.Create<T, InvokeProxy<T>>();
+
+ private class InvokeProxy<T> : DispatchProxy
+ {
+ protected override object Invoke(MethodInfo targetMethod, object[] args) => null;
+ }
+}
+
+internal class TestType_InternalProxyInternalBaseType : TestType_ExternalNonPublicBaseClassForProxy
+{
+}
+
+internal class TestType_InternalProxyImplementingInterfaceWithGenericArgumentBeingNonPublicExternalType : DispatchProxy, TestType_InternalInterfaceWithNonPublicExternalGenericArgument
+{
+ public TestType_IExternalNonPublicHiService GetInnerService() => throw new InvalidOperationException();
+
+ protected override object Invoke(MethodInfo targetMethod, object[] args)
+ {
+ throw new InvalidOperationException();
+ }
+}
+
+internal class InternalInvokeProxy : DispatchProxy
+{
+ protected override object Invoke(MethodInfo targetMethod, object[] args) => null;
+}
+
// This test double creates a proxy instance for the requested 'ProxyT' type.
// When methods are invoked on that proxy, it will call a registered callback.
public class TestDispatchProxy : DispatchProxy