Hi,
I'm trying to access the HasValue property of the generic type
Nullable<T>, but after spending hours thrashing around with the code I
just can't get it to work. The code below is the culprit, it takes a
nullable ParameterDefinition parameter and tries to invoke the HasValue
property of that parameter:
// This works, but only if the parameter is Nullable<int>
MethodReference hasValueReference =
this.module.Import(typeof(Nullable<int>).GetProperty("HasValue").GetGetMethod());
Console.WriteLine(hasValueReference.MetadataToken);
// I WANT this to work, it should be fine for any Nullable<*>. But the
metadata token is invalid (says PEVerify) and I don't have a clue what
it is or what should go in it :-)
// It defaults to Module [0x0000], but the Imported MethodReference
above has MemberRef [0x001b].. but this only works for Nullable<int>,
you can't just set it into the MethodReference below and expect it to work..
MethodReference oldHasValueReference = new
MethodReference("get_HasValue", parameter.ParameterType,
module.Import(typeof(bool)), true, false, MethodCallingConvention.Default);
Console.WriteLine(oldHasValueReference.MetadataToken);
// Then emit some code:
//Ldarga(parameter);
//Call(oldHasValueReference);
Thanks for any help you can give me on this point..
Max
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---