備忘録

備忘録

C# IL boolの戻り値を反転させる。

パターン1

bool hoge() {
  return gege();
}
// ↓こうしたい
bool hoge() {
  return !gege();
}

bool gege {
  // return false
  // または
  // return true;
}

ldc.i4.0
ceq
を追加する

call gege()
stloc.0
...
ret

↓

call gege()
ldc.i4.0
ceq
stloc.0
..
ret

パターン2

if(condition()) {
  ...
}
bfalse ...
となっているので
btrueに変更すると
if(!condition()) {
  ...
}

に変わる。