Browse Source

Add MoveElementToIndex and MoveElementToEnd methods to InstructionCollection

pull/976/head
Siegfried Pammer 8 years ago
parent
commit
372f543d6c
  1. 36
      ICSharpCode.Decompiler/IL/Instructions/InstructionCollection.cs

36
ICSharpCode.Decompiler/IL/Instructions/InstructionCollection.cs

@ -333,7 +333,41 @@ namespace ICSharpCode.Decompiler.IL @@ -333,7 +333,41 @@ namespace ICSharpCode.Decompiler.IL
}
return removed;
}
public void MoveElementToIndex(int oldIndex, int newIndex)
{
parentInstruction.AssertNoEnumerators();
var item = list[oldIndex];
Insert(newIndex, item);
if (oldIndex < newIndex)
RemoveAt(oldIndex);
else
RemoveAt(oldIndex + 1);
}
public void MoveElementToIndex(T item, int newIndex)
{
parentInstruction.AssertNoEnumerators();
int oldIndex = IndexOf(item);
if (oldIndex >= 0) {
Insert(newIndex, item);
if (oldIndex < newIndex)
RemoveAt(oldIndex);
else
RemoveAt(oldIndex + 1);
}
}
public void MoveElementToEnd(int index)
{
MoveElementToIndex(index, list.Count);
}
public void MoveElementToEnd(T item)
{
MoveElementToIndex(item, list.Count);
}
// more efficient versions of some LINQ methods:
public T First()
{

Loading…
Cancel
Save