Skip to content

Latest commit

 

History

History
75 lines (40 loc) · 3.87 KB

ii.22.20-genericparam-0x2a.md

File metadata and controls

75 lines (40 loc) · 3.87 KB

II.22.20 GenericParam: 0x2A

The GenericParam table has the following columns:

  • Number (the 2-byte index of the generic parameter, numbered left-to-right, from zero)

  • Flags (a 2-byte bitmask of type GenericParamAttributes, §II.23.1.7)

  • Owner (an index into the TypeDef or MethodDef table, specifying the Type or Method to which this generic parameter applies; more precisely, a TypeOrMethodDefII.24.2.6) coded index)

  • Name (a non-null index into the String heap, giving the name for the generic parameter. This is purely descriptive and is used only by source language compilers and by Reflection)

The following additional restrictions apply:

  • Owner cannot be a non nested enumeration type; and

  • If Owner is a nested enumeration type then Number must be less than or equal to the number of generic parameters of the enclosing class.

[Rationale: Generic enumeration types serve little purpose and usually only exist to meet CLS Rule 42. These additional restrictions limit the genericty of enumeration types while allowing CLS Rule 42 to be met. The GenericParam table stores the generic parameters used in generic type definitions and generic method definitions. These generic parameters can be constrained (i.e., generic arguments shall extend some class and/or implement certain interfaces) or unconstrained. (Such constraints are stored in the GenericParamConstraint table.)

Conceptually, each row in the GenericParam table is owned by one, and only one, row in either the TypeDef or MethodDef tables.

[Example:

.class Dict`2<([mscorlib]System.IComparable) K, V>

The generic parameter K of class Dict is constrained to implement System.IComparable.

.method static void ReverseArray<T>(!!0[] 'array')

There is no constraint on the generic parameter T of the generic method ReverseArray. end example]

This contains informative text only.

  1. GenericParam table can contain zero or more rows

  2. Each row shall have one, and only one, owner row in the TypeDef or MethodDef table (i.e., no row sharing) [ERROR]

  3. Every generic type shall own one row in the GenericParam table for each of its generic parameters [ERROR]

  4. Every generic method shall own one row in the GenericParam table for each of its generic parameters [ERROR]

Flags:

  1. Can hold the value Covariant or Contravariant, but only if the owner row corresponds to a generic interface, or a generic delegate class. [ERROR]

  2. Otherwise, shall hold the value None indicating nonvariant (i.e., where the parameter is nonvariant or the owner is a non delegate class, a value-type, or a generic method) [ERROR]

  3. If Flags == Covariant then the corresponding generic parameter can appear in a type definition only as: [ERROR]

    • The result type of a method

    • A generic parameter to an inherited interface

  4. If Flags == Contravariant then the corresponding generic parameter can appear in a type definition only as the argument to a method [ERROR]

  5. Number shall have a value ≥ 0 and < the number of generic parameters in owner type or method. [ERROR]

  6. Successive rows of the GenericParam table that are owned by the same method shall be ordered by increasing Number value; there shall be no gaps in the Number sequence [ERROR]

  7. Name shall be non-null and index a string in the String heap [ERROR]

    [Rationale: Otherwise, Reflection output is not fully usable. end rationale]

  8. There shall be no duplicate rows based upon Owner+Name [ERROR]

    [Rationale: Otherwise, code using Reflection cannot disambiguate the different generic parameters. end rationale]

  9. There shall be no duplicate rows based upon Owner+Number [ERROR]

End informative text.