From d52586353dc0634512222ca8cc8d7000ce29cfc9 Mon Sep 17 00:00:00 2001 From: Oluwatoni Solarin-Sodara Date: Fri, 23 Mar 2018 00:36:19 +0100 Subject: [PATCH] ensure instrumentation code becomes the new target --- .../Instrumentation/Instrumenter.cs | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/coverlet.core/Instrumentation/Instrumenter.cs b/src/coverlet.core/Instrumentation/Instrumenter.cs index 0a0d53a82..5e8d9dbd8 100644 --- a/src/coverlet.core/Instrumentation/Instrumenter.cs +++ b/src/coverlet.core/Instrumentation/Instrumenter.cs @@ -138,20 +138,21 @@ private Instruction AddInstrumentationCode(MethodDefinition method, ILProcessor private void ReplaceInstructionTarget(Instruction instruction, Instruction oldTarget, Instruction newTarget) { - if (!(instruction.Operand is Instruction _instruction) - || !(instruction.Operand is Instruction[] _instructions)) - return; - - if (_instruction == oldTarget) + if (instruction.Operand is Instruction _instruction) { - instruction.Operand = newTarget; - return; + if (_instruction == oldTarget) + { + instruction.Operand = newTarget; + return; + } } - - for (int i = 0; i < _instructions.Length; i++) + else if (instruction.Operand is Instruction[] _instructions) { - if (_instructions[i] == oldTarget) - _instructions[i] = newTarget; + for (int i = 0; i < _instructions.Length; i++) + { + if (_instructions[i] == oldTarget) + _instructions[i] = newTarget; + } } }