private void executeRemoveInstruction(ModelMap map, ModelMap overrides, ModelMapDiffOptions options, ConfiguredRemoval remove) { var targetIndex = 0; var mapInstructions = map.Instructions.ToList(); var sets = new List <InstructionSet>(); foreach (var instruction in overrides.Instructions) { if (shouldOffset(instruction, options)) { var i = mapInstructions.IndexOf(instruction); if (i != -1) { targetIndex = i; } else { targetIndex += 1; } } if (instruction.GetType().CanBeCastTo(remove.InstructionType)) { var removal = instruction as IModelMapRemovalInstruction; if (removal != null) { var set = remove.Find(map, removal.Key, targetIndex); sets.Add(set); } } } var offset = 0; foreach (var set in sets) { map.Remove(set, offset); offset += set.Instructions.Count(); } }