Greetings,

I have run into an issue getting the type of a generic parameter using the MetaData API.

When parsing the signature of a method with generic parameters and generic arguments, which is defined in a class with different generic parameters, I run into some troubled waters when I get to theELEMENT_TYPE_VAR of the generic type. The 'docs' state that the next segment of the signature defines an index - but I don't see anywhere how to use this index to lookup the type precisely - i.e. is the index part of the methods generic parameters or the defining class generic parameters.

An example:

Say I have a C# class like so:

class GenericClass<TClass, SClass, PClass>
{
public void GenericMethod<UMethod, RMethod>(SClass SomeArg, RMethod SomeOtherArg)
{
}
}

When parsing the signature and getting to the SClass SomeArg argument I get an index of 1 from the signature - but how do I figure out where this 1 belongs - the class (as is the case) or the method ?

From studying the SSCLI implementation of ILDASM I can see that it depends on an internal interface (IMDInternalImport) to make the distinction - anything similar in non-internal land or are there any other methods of doing this (have to be unmanaged - non reflection).
Regards,

Skov

Answers

  • Tuesday, September 08, 2009 4:48 PMKarel ZikmundMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Skov,
    ELEMENT_TYPE_VAR refers to the classgeneric variable. ELEMENT_TYPE_MVAR refers to methodgeneric variable.
    For more details see CLI ECMA specification (http://www.ecma-international.org/publications/standards/Ecma-335.htm), chapter II.23.1.16 "Element types used in signatures":
    ELEMENT_TYPE_VAR - 0x13 - Generic parameter in a generic type definition, represented as number
    ELEMENT_TYPE_MVAR - 0x1e - Generic parameter in a generic method definition, represented as number

    The following chapter should be useful reading too (II.23.2 "Blobs and signatures").

    -Karel

All Replies

  • Tuesday, September 08, 2009 4:48 PMKarel ZikmundMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Hello Skov,
    ELEMENT_TYPE_VAR refers to the classgeneric variable. ELEMENT_TYPE_MVAR refers to methodgeneric variable.
    For more details see CLI ECMA specification (http://www.ecma-international.org/publications/standards/Ecma-335.htm), chapter II.23.1.16 "Element types used in signatures":
    ELEMENT_TYPE_VAR - 0x13 - Generic parameter in a generic type definition, represented as number
    ELEMENT_TYPE_MVAR - 0x1e - Generic parameter in a generic method definition, represented as number

    The following chapter should be useful reading too (II.23.2 "Blobs and signatures").

    -Karel
  • Wednesday, September 09, 2009 12:44 AMS. Skov Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    ahh of course - just as the specs say..;)

    Thanks Karel!