Jb Evain wrote:
> Hi Max,
>
> You have to create a new MethodReference, with a declaring type being
> the type of the parameter which is the nullable generic instance.
>   
JB, do you mean like this? (copied from OP):

> // This works, but only if the parameter is Nullable<int>
> MethodReference hasValueReference =
> this.module.Import(typeof(Nullable<int>).GetProperty("HasValue").GetGetMethod());
>
> // 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 :)
> MethodReference hasValueReference = new
> MethodReference("get_HasValue", parameter.ParameterType,
> module.Import(typeof(bool)), true, false, MethodCallingConvention.Default);
>


> The best way to have something running, is to write what you want to
> have as a result, read the assembly with Cecil, analyse the code that
> is read and that will be generated, and do the same.
>   
I have already verified that I am generating the right code, except that
the MetadataToken is incorrect in the IL generated by Cecil for the code
I "WANT" to work above. Please can you advise me at to what it should be
for my situation?

Cheers,
Max



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

Reply via email to