On Mon, Aug 9, 2010 at 5:43 PM, Timwi <[email protected]> wrote:
> I’m surprised at your response, for two reasons. 1: because most
> GenericInstanceType instances /do/ have the GenericParameter
> collection filled correctly, with the same number of elements as
> GenericArguments. 2: because I thought I posted here about this
> earlier and I thought you fixed it. Here’s why this is necessary:

Then 1: would be a bug and 2: is a misunderstanding.

> Suppose the assembly I’m reading contains something like this...
>
>   public class X<T> {
>      public T Method() { return default(T); }
>   }
>
>   static class Program {
>      static void Main() {
>         X<int> x = new X<int>();
>         int y = x.Method();          // !
>      }
>   }
>
> In the line marked "!", what is the operand to the IL “call”
> instruction? It’s a MethodReference whose DeclaringType is a
> GenericInstanceType. Furthermore, what is the return type of that
> MethodReference? It’s not “int”, it’s a GenericParameter instance
> named “!0”.

> HOWEVER, it is NOT the same GenericParameter instance that I get from
> the TypeDefinition for X<T>. They have a different Owner property
> value: The latter’s owner is X`1 (TypeDefinition), but the former’s is
> X`1<Int32> (GenericInstanceType). Therefore, I cannot compare them as
> equal.

This is definitely not what's happening with Cecil on HEAD.

The call:

>         int y = x.Method();          // !

Gets encoded as a MemberReference with a declaring type being a
GenericInstanceType which has zero items in its .GenericParameters
collection.

The return type if the GenericParameter T owned by X`1.

Have you bothered to update? Also I can read words that are normally
cased just fine.

> You must be generating this other GenericParameter instance somewhere,
> and it seems that most of the time it gets added to the
> GenericParameters collection, but sometimes it doesn’t?

If you have a GenericInstanceType or GenericInstanceMethod, don't
access their .GenericParameters, use their
.ElementType.GenericParameters if you have to. But it makes no sense
for a generic instance to declare a generic parameter.

-- 
Jb Evain  <[email protected]>

-- 
--
mono-cecil

Reply via email to