PageRenderTime 26ms CodeModel.GetById 17ms app.highlight 4ms RepoModel.GetById 2ms app.codeStats 0ms

/Main/src/DynamicDataDisplay/Common/Auxiliary/NotifyCollectionChangedEventArgsExtensions.cs

#
C# | 29 lines | 24 code | 5 blank | 0 comment | 2 complexity | 3b1e528c1162409b281d1dcc2ef386c3 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.Collections.Specialized;
 6using Microsoft.Research.DynamicDataDisplay.Charts;
 7
 8namespace Microsoft.Research.DynamicDataDisplay.Common.Auxiliary
 9{
10	public static class NotifyCollectionChangedEventArgsExtensions
11	{
12		public static int GetLastAddedIndex(this NotifyCollectionChangedEventArgs args)
13		{
14			if (args.NewItems == null)
15				throw new InvalidOperationException("Cannot get last added index when NewItems are null.");
16
17			int lastIndex = args.NewStartingIndex + args.NewItems.Count;
18
19			return lastIndex;
20		}
21
22		public static Range<int> GetAddedRange(this NotifyCollectionChangedEventArgs args)
23		{
24			int lastIndex = GetLastAddedIndex(args);
25
26			return new Range<int>(args.NewStartingIndex, lastIndex);
27		}
28	}
29}