/// <summary> /// Emit code within the method body. /// </summary> /// <param name="code">The code.</param> public CodeEmitter Emit(Instruction code) { if (code == null) { return(this); } if (Insert != CodeInsertion.Append && Position == null) { throw new NotSupportedException($"Cannot insert relative to a position without a position (mode is {Insert} in {Parent.Target.FullName})"); } switch (Insert) { case CodeInsertion.After: IL.InsertAfter(Position, code); Position = code; break; case CodeInsertion.Append: IL.Append(code); break; case CodeInsertion.Before: IL.InsertBefore(Position, code); break; } if (tryBlocks.Count > 0) { var block = tryBlocks.Peek(); switch (block.State) { case 0: block.TryEnd = code; break; case 1: block.CatchEnd = code; break; case 2: block.FinallyEnd = code; break; } } return(this); }