This is what the original type looks like before running it through
Cecil:

public class Sample<T>
{
}

This is what it should look like after Cecil (the C# equivalent):

public class Sample<T>
{
     bool IsInterceptionEnabled { get; set; }
}


Here is the ILDASM dump from both the getter and the setter methods:

.method public hidebysig newslot specialname virtual
        instance bool  get_IsInterceptionEnabled() cil managed
{
  // Code size       7 (0x7)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldfld      bool
TestLibrary.New`1::__IsInterceptionEnabled_backingField
  IL_0006:  ret
} // end of method New`1::get_IsInterceptionEnabled


.method public hidebysig newslot specialname virtual
        instance void  set_IsInterceptionEnabled(bool A_1) cil managed
{
  // Code size       8 (0x8)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldarg.1
  IL_0002:  stfld      bool
TestLibrary.New`1::__IsInterceptionEnabled_backingField
  IL_0007:  ret
} // end of method New`1::set_IsInterceptionEnabled

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.

[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.

As a test, I ran the following code through the C# compiler:

public class Sample<T>
{
     bool IsInterceptionEnabled { get; set; }
}

The ILDASM dump looks like this:

.method private hidebysig specialname instance bool
        get_IsInterceptionEnabled() cil managed
{
  .custom instance void
[mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
= ( 01 00 00 00 )
  // Code size       11 (0xb)
  .maxstack  1
  .locals init (bool V_0)
  IL_0000:  ldarg.0
  IL_0001:  ldfld      bool class AopBench2.Sample`1<!
T>::'<IsInterceptionEnabled>k__BackingField'
  IL_0006:  stloc.0
  IL_0007:  br.s       IL_0009
  IL_0009:  ldloc.0
  IL_000a:  ret
} // end of method Sample`1::get_IsInterceptionEnabled

.method private hidebysig specialname instance void
        set_IsInterceptionEnabled(bool 'value') cil managed
{
  .custom instance void
[mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor()
= ( 01 00 00 00 )
  // Code size       8 (0x8)
  .maxstack  8
  IL_0000:  ldarg.0
  IL_0001:  ldarg.1
  IL_0002:  stfld      bool class AopBench2.Sample`1<!
T>::'<IsInterceptionEnabled>k__BackingField'
  IL_0007:  ret
} // end of method Sample`1::set_IsInterceptionEnabled

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.




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

Reply via email to