です。タイプからプロキシを構築するコードがあります。それは完全に動作します。 次に、コール時にisDirtyビットをプッシュする必要があるsetter emitコードを追加しました。これは失敗します、なぜですか?実行時にemitコードがクラッシュしますが、デバッグでは発生しません。理由は
isDirtyビットを付けずにコードを実行すると動作します。 isDirtyビットでコードを実行すると、デバッグでは動作しますが、ビジュアルスタジオで逆アセンブリウィンドウが起動します。 isDirty(デバッグなし)のコードを実行するとプログラムがクラッシュする(応答しない)が、取り消しを押すと作業が開始され、rigthデータがすべて表示されます。
PropertyBuilder property = proxy.DefineProperty(propertyInfo.Name, propertyInfo.Attributes, propertyInfo.PropertyType, null);
MethodAttributes attributes = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.Virtual;
MethodBuilder setMethod = proxy.DefineMethod("set_" + propertyInfo.Name, attributes, typeof(void), new Type[] { propertyInfo.PropertyType });
ILGenerator setIL = setMethod.GetILGenerator();
setIL.Emit(OpCodes.Ldarg_0); // load this on the stack - where this is the type we are creating
setIL.Emit(OpCodes.Ldarg_1); // load first parameter on the stack
setIL.Emit(OpCodes.Call, propertyInfo.GetSetMethod());
{
//error here: when this is uncomment, it fails
// // set the isDirty bit
// setIL.Emit(OpCodes.Ldarg_0); // load this on the stack
// setIL.Emit(OpCodes.Ldc_I4_1, 1); // push a number on the stack
// setIL.Emit(OpCodes.Stfld, isDirtyField); // save the value on the stack in field
}
setIL.Emit(OpCodes.Ret);
property.SetSetMethod(setMethod);
これはなぜ失敗するのですか?専門家:)
//デニス
私は何をしていたのかを知っていました。私はそれを積極的に価値あるものに押しつけるだけでなく、値を提供しています。それとも私は思う。 しかし、それは動作します。どうも –