forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed Emit MethodInfo for interface generic
Signature generation now includes CustomModifiers MethodBuilder and ConstructorBuilder passes their SignatureHelper for generation Fixes dotnet#25958
- Loading branch information
Showing
6 changed files
with
196 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/libraries/System.Reflection.Emit.ILGeneration/tests/ILGenerator/EmitMethodInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// 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.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace System.Reflection.Emit.Tests | ||
{ | ||
public class ILGeneratorEmitMethodInfo | ||
{ | ||
public interface IWithIn<T> | ||
{ | ||
void Method(in RuntimeMethodHandle arg); | ||
} | ||
|
||
public sealed class WithIn : IWithIn<int> | ||
{ | ||
public void Method(in RuntimeMethodHandle arg) | ||
{ | ||
|
||
} | ||
} | ||
|
||
[Fact] | ||
public void EmitMethodInfo() | ||
{ | ||
var testInstance = new WithIn(); | ||
var methodType = typeof(IWithIn<int>); | ||
var method = methodType.GetMethod("Method"); | ||
|
||
ModuleBuilder moduleBuilder = Helpers.DynamicModule(); ; | ||
var typeBuilder = moduleBuilder.DefineType("DynamicType", TypeAttributes.Public); | ||
|
||
var methodBuilder = typeBuilder.DefineMethod("Call", MethodAttributes.Public | MethodAttributes.Static, null, new Type[] { typeof(IWithIn<int>) }); | ||
|
||
var ilBuilder = methodBuilder.GetILGenerator(); | ||
ilBuilder.Emit(OpCodes.Ldarg_0); | ||
ilBuilder.Emit(OpCodes.Ldtoken, method); | ||
ilBuilder.Emit(OpCodes.Callvirt, method); | ||
ilBuilder.Emit(OpCodes.Ret); | ||
|
||
var type = typeBuilder.CreateType(); | ||
var genMethod = type.GetMethod("Call"); | ||
genMethod.Invoke(null, new object[] { testInstance }); | ||
|
||
var il = genMethod.GetMethodBody().GetILAsByteArray(); | ||
|
||
var ilMethodMetadataToken = BitConverter.ToInt32(il, 2); | ||
var resolvedMethod = type.Module.ResolveMethod(ilMethodMetadataToken); | ||
Assert.Equal(method, resolvedMethod); | ||
ilMethodMetadataToken = BitConverter.ToInt32(il, 7); | ||
resolvedMethod = type.Module.ResolveMethod(ilMethodMetadataToken); | ||
Assert.Equal(method, resolvedMethod); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters