부울 필드가 거짓이면 확인하고 싶습니다. 그러나 나는 그것을 작동시킬 수 없다.C# emit bool 필드를 검사하여 레이블로 나눕습니다.
그래서 스택에 bool 필드를 푸시하고 Brtrue_S를 호출하고 싶습니다. 값이 true 또는 null이 아닌 컨트롤을 넘겨 줄 것입니다. 하지만 실패합니다. 이 코드는 스택에 int, push라고 부르는 것만으로도 작동합니다. 왜 부울이 아닌가?
나는 unbox_any를 시도해 봤지만 이것이 얼마나 좋은지는 잘 모른다.
FieldBuilder fieldId = proxy.DefineField("Is" + property.Name + "Init", typeof (Boolean),
FieldAttributes.Private);
Label ExitIfStatement = getIL.DefineLabel();
//getIL.Emit(OpCodes.Ldc_I4_0); // push 0 to the eval stack, this WORKS FINE!
//getIL.Emit(OpCodes.Ldfld, fieldId); // push 0 to the eval stack // THIS FAILD, WHY ?
getIL.Emit(OpCodes.Brtrue_S, ExitIfStatement); // if is[propertyName]init == true goto MarkLabel(ExitIfStatement)
getIL.EmitWriteLine("Test if null is true");
getIL.Emit(OpCodes.Nop);
getIL.MarkLabel(ExitIfStatement);
getIL.EmitWriteLine("Test if null: false");
getIL.Emit(OpCodes.Nop);
getIL.Emit(OpCodes.Ldarg_0); // push the type on stack we need it to call base property
getIL.Emit(OpCodes.Call, propertyInfo.GetGetMethod()); // TEST CODE
getIL.Emit(OpCodes.Ret);
들으을 "객체가 null로, 필드가 정적이 아닌 경우는 NullReferenceException가 슬로우됩니다." –