2011-01-21 130 views
4

動搖我跟着提示here,我甚至把以下行:Mono.Cecil能:操作可以在運行時

var MSILWorker = prop.SetMethod.Body.GetILProcessor(); 
MSILWorker.Body.InitLocals = true; 

我有兩個類的兩個屬性:

[NotifyProperty] 
public int Number { get; set; } 

[NotifyProperty] 
public string Name { get; set; } 

生成的IL代碼是完全相同的,除了當然在名稱的屬性和d後臺字段的類型。然而,第一個拋出了VerificationException(「操作可能會破壞運行時的穩定性」),第二個不會。 我可能做錯了什麼?

編輯:這裏是有問題的IL:

.method public hidebysig specialname instance void set_Number(int32 'value') cil managed 
{ 
    .custom instance void [mscorlib]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() 
    .maxstack 3 
    L_0000: nop 
    L_0001: ldarg.0 
    L_0002: ldarg.1 
    L_0003: stfld int32 TestApplication.SLTest.SLBOComposite::<Number>k__BackingField 
    L_0008: ldarg.0 
    L_0009: ldstr "Number" 
    L_000e: call instance void TestApplication.SLTest.SLBOComposite::RaisePropertyChanged(string) 
    L_0013: nop 
    L_0014: ldarg.0 
    L_0015: ldstr "Number" 
    L_001a: ldarg.1 
    L_001b: call instance void W3B.TestApplication.SLTest.SLBOComposite::Validate(string, object) 
    L_0020: nop 
    L_0021: ret 
} 

回答

3

沒關係。 :)

L_001b: box int32 

有解決方案。

相關問題