PageRenderTime 15ms CodeModel.GetById 12ms app.highlight 2ms 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
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5
 6namespace Microsoft.Research.DynamicDataDisplay.Common.UndoSystem
 7{
 8	public sealed class CollectionAddAction<T> : UndoAction
 9	{
10		private readonly ICollection<T> collection;
11		private readonly T item;
12
13		public CollectionAddAction(ICollection<T> collection, T item)
14		{
15			if (collection == null)
16				throw new ArgumentNullException("collection");
17			if (item == null)
18				throw new ArgumentNullException("addedItem");
19
20			this.collection = collection;
21			this.item = item;
22		}
23
24		public override void Do()
25		{
26			collection.Add(item);
27		}
28
29		public override void Undo()
30		{
31			collection.Remove(item);
32		}
33	}
34}