public Cut Write(Instruction instruction) { CutEvents.OnModify(_body); if (_entry) { Instructions.Insert(0, instruction); foreach (var handler in _body.ExceptionHandlers.Where(h => h.HandlerStart == null).ToList()) { handler.HandlerStart = _refInst; } } else if (_exit || _refInst == Instructions[Instructions.Count - 1]) { Instructions.Add(instruction); if (!_exit) { foreach (var handler in _body.ExceptionHandlers.Where(h => h.HandlerEnd == null).ToList()) { handler.HandlerEnd = _refInst; } } } else { var index = Instructions.IndexOf(_refInst) + 1; Instructions.Insert(index, instruction); } return(new Cut(_body, instruction)); }
public Cut Remove() { CutEvents.OnModify(_body); var prevCut = Prev(); var next = _refInst.Next; var prev = _refInst.Previous; Redirect(_refInst, next, prev); Instructions.Remove(_refInst); return(prevCut); }
public Cut Replace(Instruction instruction) { CutEvents.OnModify(_body); if (_exit || _entry) { return(Write(instruction)); } Redirect(_refInst, instruction, instruction); Instructions[Instructions.IndexOf(_refInst)] = instruction; return(new Cut(_body, instruction)); }