Jb Evain wrote:
> Max,
>
> On 6/21/07, Max Bolingbroke <[EMAIL PROTECTED]> wrote:
>
>> MethodReference constructorReference = new MethodReference(".ctor",
>> typeWhichIsIndeedANullableTypeInstance, module.Import(typeof(void)),
>> true, false, MethodCallingConvention.Default);
>> constructorReference.Parameters.Add(new
>> ParameterDefinition(typeWhichIsIndeedANullableTypeInstance.GenericParameters[0]));
>>
>
> In this code, how is initialized typeWhichIsIndeedANullableTypeInstance?
>
> I can't repro the bug where the GenericInstanceType have a value in
> its GenericParameter collection.
>
Hi,
I made a mistake when reporting the problem in my original post, which
is why you cannot reproduce it: many apologies. This was my actual problem:
MethodReference constructorReference = new
MethodReference(Constructors.InstanceConstructorName,
parameter.ParameterType, module.Import(typeof(void)), true, false,
MethodCallingConvention.Default);
// System.Nullable`1<System.Int32>
Console.WriteLine(parameter.ParameterType.FullName);
// Mono.Cecil.GenericInstanceType
Console.WriteLine(parameter.ParameterType.GetType());
// 0
Console.WriteLine(parameter.ParameterType.GenericParameters.Count);
// 1
Console.WriteLine(((GenericInstanceType)parameter.ParameterType).GenericArguments.Count);
TypeReference genericTokenTypeReference =
parameter.ParameterType.GenericParameters[0]; //
ArgumentOutOfRangeException, since there is no GenericParameter
constructorReference.Parameters.Add(new
ParameterDefinition(genericTokenTypeReference));
However, I assume this is the intended behaviour. I have managed to fix
my code now by using the ElementType you mentioned.. I had assumed (from
the name) that it was only for the TypeReference of the elements of
arrays (e.g. int for int[]), and this was further reinforced by the fact
that it was declared not on GenericInstanceType but on TypeSpecification.
Anyway, thanks a lot for your help! My code now verifies with the
exception of all the duplicate MemberRefs, which are just warnings: I
had indeed noticed, as you point out, that MemberReferences.Contains
doesn't do what the name suggests. It might be helpful to provide
factory methods for MethodReferences on the Module, which also add them
to the references collection. Then at assembly save time duplicates in
this collection could be ignored, since they are always an error to
include. I think this is the best you would be able to do, since
MethodReferences are mutable classes..
Cheers,
Max
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---