Hi
I thought I had generics in Mono.Cecil figured out, but apparently
not!
I'm trying to add a nested stub class for a method:
class A<T>
{
void M() {}
}
needs to become:
class A<T>
{
void M() {}
class M_stub<T> {}
}
This is the relevant piece of code I'm using:
string name = method.Name + "_stub";
var stubType = new TypeDefinition(name, "",
TypeAttributes.NestedPrivate, _objType);
foreach (GenericParameter p in method.DeclaringType.GenericParameters)
{
stubType.GenericParameters.Add(new GenericParameter(p.Name,
stubType));
}
_assembly.MainModule.Types.Add(stubType);
method.DeclaringType.NestedTypes.Add(stubType);
Looks like it does not work when the # of generic parameters is more
than one - getting following errors with peverify.
[MD]: Error: GenericParam is out of sequence by owner. [token:
0x2A000003]
[MD]: Error: GenericParam is out of sequence by number. [token:
0x2A000003]
When I pull the modified assembly in reflector:
class A<T, U>
{
void M() {}
}
somehow becomes:
class A<T, U>
{
void M() {}
class M_stub<U, T> {}
}
The order of parameters in the nested class seems to get reversed, and
I'm guessing that's the reason for the peverify error.
Can somebody point out what I'm doing wrong here?
Thanks
Ajai
--
--
mono-cecil