Mono.Cecil:操作可能会在运行时失去稳定性

时间:2011-01-21 12:59:36

标签: c# inotifypropertychanged cil mono.cecil

我按照提示here,我甚至将以下几行放在:

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

我在两个类中有两个属性:

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

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

生成的IL代码完全相同,当然除了属性名称和支持字段的类型。然而第一个抛出VerificationException(“操作可能破坏运行时”),第二个抛出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 
}

1 个答案:

答案 0 :(得分:3)

没关系。 :)

 L_001b: box int32

有解决方案。