Reputation: 312
I'm 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 inspect this IL, I see that the operand of the instruction is a GenericInstanceMethod, which holds an ElementMethod of type MethodReference. This MethodReference in turn has a return type of type GenericParameter.
I'd like to create the same objects by hand, but reach a catch-22 it seems. To create a GenericParameter, I need an IGenericParameterOwner, which seems to be the very same MethodReference above. So I'd like to pass the MethodReference to the GenericParameter constructor. However, I can't create the MethodReference without a TypeReference for the return type either, which I assume should be the GenericParameter.
How do I resolve this? What I am misunderstanding?
Upvotes: 5
Views: 945
Reputation: 17499
This seems to be an issue with the API as it is.
An easy way to work around this would be to pass a TypeReference to void as the ReturnType of your MethodReference, and change the ReturnType to the later created GenericParameter.
Upvotes: 5