Google
❔ How do I make these two codes less copy pasta?
void Redo()
{
var thingToUnreverse = Actions[CurrentActionStep + 1];
foreach (var thing in thingToUnreverse.thingsMoved)
{
var bvmToMove = objectCollection.FirstOrDefault(bvm => bvm.Guid == thing.objectViewModel.Guid);
if (bvmToMove is null) { continue; }
bvmToMove.Position = thing.NewPosition;
} //There are also a dozen other operations that occur here.
}
void Undo()
{
var thingToReverse = Actions[CurrentActionStep];
foreach (var thing in thingToReverse.thingsMoved)
{
var bvmToMove = objectCollection.FirstOrDefault(bvm => bvm.Guid == thing.objectViewModel.Guid);
if (bvmToMove is null) { continue; }
bvmToMove.Position = thing.OldPosition;
}
}
void Redo()
{
var thingToUnreverse = Actions[CurrentActionStep + 1];
foreach (var thing in thingToUnreverse.thingsMoved)
{
var bvmToMove = objectCollection.FirstOrDefault(bvm => bvm.Guid == thing.objectViewModel.Guid);
if (bvmToMove is null) { continue; }
bvmToMove.Position = thing.NewPosition;
} //There are also a dozen other operations that occur here.
}
void Undo()
{
var thingToReverse = Actions[CurrentActionStep];
foreach (var thing in thingToReverse.thingsMoved)
{
var bvmToMove = objectCollection.FirstOrDefault(bvm => bvm.Guid == thing.objectViewModel.Guid);
if (bvmToMove is null) { continue; }
bvmToMove.Position = thing.OldPosition;
}
}
17 replies