1

I have the following class:

public class MyGenericArray<T>
{
    private T[] array;

    public MyGenericArray(int size)
    {
        array = new T[size + 1];
    }

    public T getItem(int index)
    {
        var in2 = index + 1;
        in2 = index - in2;
        index = index + 1 - in2 - 1;
        return array[index];
    }
}

I use dnlib to make some changes at the cil code level. Inside the getItem() method, I want to get the class type of the this parameter, ldarg.0.

I am looking in the param.Type where

param = ((Parameter)_instruction.Operand);

I have searched through all the available fields but I could not find it. In fact, what I get is

 ConsoleCalculator.BasicTests/MyGenericArray`1

and I expect to find

 ConsoleCalculator.BasicTests/MyGenericArray`1<!T>

I don't understand why the <!T> is missing.

For the field private T[] array; the class is displayed correctly, with the <!T> at the end.

cipri.l
  • 819
  • 10
  • 22

1 Answers1

1
GenericVar[] genArgs = new GenericVar[typeDef.GenericParameters.Count];
        for (int i = 0; i < genArgs.Length; i++)
            genArgs[i] = new GenericVar(i);

GenericInstSig genericInstanceType = new GenericInstSig((ClassOrValueTypeSig) methodDef.DeclaringType.ToTypeSig(), genArgs);
Cipher
  • 352
  • 1
  • 11