void RewriteAsIsInst(ref BasicBlock block) { Scanner.LogDebug(1, $"REWRITE AS ISINST: {block.Count} {block}"); var reference = Assembly.MainModule.ImportReference(InstanceType); int index = 1; BlockList.InsertInstructionAt(ref block, index++, Instruction.Create(OpCodes.Isinst, reference)); BlockList.InsertInstructionAt(ref block, index++, Instruction.Create(OpCodes.Dup)); BlockList.ReplaceInstructionAt(ref block, index++, Instruction.Create(OpCodes.Stloc, Variable)); BlockList.RemoveInstructionAt(ref block, index); switch (block.BranchType) { case BranchType.False: case BranchType.True: break; case BranchType.None: case BranchType.Return: // Convert it into a bool. BlockList.InsertInstructionAt(ref block, index++, Instruction.Create(OpCodes.Ldnull)); BlockList.InsertInstructionAt(ref block, index++, Instruction.Create(OpCodes.Cgt_Un)); break; default: throw DebugHelpers.AssertFailUnexpected(Method, block, block.BranchType); } }