PageRenderTime 34ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Common/UndoSystem/CollectionAddAction.cs

#
C# | 34 lines | 29 code | 5 blank | 0 comment | 4 complexity | 9f96a85ccaad484e402d56ed81585ba8 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. namespace Microsoft.Research.DynamicDataDisplay.Common.UndoSystem
  6. {
  7. public sealed class CollectionAddAction<T> : UndoAction
  8. {
  9. private readonly ICollection<T> collection;
  10. private readonly T item;
  11. public CollectionAddAction(ICollection<T> collection, T item)
  12. {
  13. if (collection == null)
  14. throw new ArgumentNullException("collection");
  15. if (item == null)
  16. throw new ArgumentNullException("addedItem");
  17. this.collection = collection;
  18. this.item = item;
  19. }
  20. public override void Do()
  21. {
  22. collection.Add(item);
  23. }
  24. public override void Undo()
  25. {
  26. collection.Remove(item);
  27. }
  28. }
  29. }