Hey,

Your mail is as confused as what's your trying to accomplish is
confusing as well as this sentence is.

What about writing the code you want to generate in C#, so that we can
try to understand what you're trying to do?

On 6/11/07, Max Bolingbroke <[EMAIL PROTECTED]> wrote:
> 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

-- 
Jb

--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---

Reply via email to