Hi Philip,
> The IL itself is pretty straightforward, but once I run it through
> PEVerify, it gives me the following error:
>
> [IL]: Error: [D:\Development\TestBed4\TestBed4\bin\Debug
> \testlibrary.dll : TestL
> ibrary.New`1[T]::get_IsInterceptionEnabled][offset
> 0x00000001]System.BadImageFor
> matException: Fields inside generic classes must be referenced using
> MemberRefs,
> even in the same module as the class. [HRESULT 0x8007000B] - An
> attempt was ma
> de to load a program with an incorrect format.
It looks pretty simple to workaround, you cannot ldfld the field
definition here, you have to create a MemberReference with the same
name, and with the appropriate DeclaringType (which may or may not be
a GenericInstanceType)
> public class Sample<T>
> {
> bool IsInterceptionEnabled { get; set; }
> }
>
> Now, from what I can tell, the only difference here is that the actual
> C# compiler is loading the backing field using the '!T' type parameter
> instead of using the naked generic type definition. Does anyone know
> if there is there a fix for this, or is there some sort of workaround
> for it? Thanks in advance.
Your best chance here is, as you did, to write the C# equivalent of
what you want to generate, then dump the Cecil structure that you read
from this equivalent, so that you can generate the same.
In this case, a MemberReference with the good declaring type.
--
Jb Evain <[EMAIL PROTECTED]>
--~--~---------~--~----~------------~-------~--~----~
--
mono-cecil
-~----------~----~----~----~------~----~------~--~---