How to create GenericParameter return type for Method method in Mono.Cecil?

I am trying to reproduce the following IL using Mono.Cecil:

call !!0 [mscorlib]System.Threading.Interlocked::CompareExchange<class [System]System.ComponentModel.PropertyChangedEventHandler>(!!0&, !!0, !!0) 

When I use Mono.Cecil to test this IL, I see that the operand of the command is GenericInstanceMethod, which contains an ElementMethod of type MethodReference. This Reference method, in turn, has a GenericParameter return type.

I would like to create the same objects manually, but get to catch-22. To create a GenericParameter, I need an IGenericParameterOwner, which seems to be the same MethodReference method above. Therefore, I would like to pass a MethodReference to the GenericParameter constructor. However, I cannot create a MethodReference without a TypeReference for the return type, which I suppose should be a GenericParameter.

How do i solve this? What do I misunderstand?

+4
source share
1 answer

This seems to be a problem with the API as it is.

An easy way around this would be to pass the TypeReference to void as the ReturnType of your MethodEeference method and change the ReturnType to a later created GenericParameter.

+4
source

Source: https://habr.com/ru/post/1398310/


All Articles