PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 1ms 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
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. using System.Collections.Specialized;
  6. using Microsoft.Research.DynamicDataDisplay.Charts;
  7. namespace Microsoft.Research.DynamicDataDisplay.Common.Auxiliary
  8. {
  9. public static class NotifyCollectionChangedEventArgsExtensions
  10. {
  11. public static int GetLastAddedIndex(this NotifyCollectionChangedEventArgs args)
  12. {
  13. if (args.NewItems == null)
  14. throw new InvalidOperationException("Cannot get last added index when NewItems are null.");
  15. int lastIndex = args.NewStartingIndex + args.NewItems.Count;
  16. return lastIndex;
  17. }
  18. public static Range<int> GetAddedRange(this NotifyCollectionChangedEventArgs args)
  19. {
  20. int lastIndex = GetLastAddedIndex(args);
  21. return new Range<int>(args.NewStartingIndex, lastIndex);
  22. }
  23. }
  24. }