> GenericInstanceType don't have parameters, they have arguments.

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:

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.

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?

-- 
--
mono-cecil

Reply via email to