/// <summary> /// Gets the type of the change i.e. whether it is an item or a range change /// </summary> /// <param name="source">The source.</param> /// <returns></returns> /// <exception cref="System.ArgumentOutOfRangeException"></exception> public static ChangeType GetChangeType(this ListChangeReason source) { switch (source) { case ListChangeReason.Add: return(ChangeType.Item); case ListChangeReason.AddRange: return(ChangeType.Range); case ListChangeReason.Replace: return(ChangeType.Item); case ListChangeReason.Remove: return(ChangeType.Item); case ListChangeReason.RemoveRange: return(ChangeType.Range); case ListChangeReason.Moved: return(ChangeType.Item); case ListChangeReason.Clear: return(ChangeType.Range); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Initializes a new instance of the <see cref="ItemChange{T}"/> struct. /// </summary> /// <param name="reason">The reason.</param> /// <param name="current">The current.</param> /// <param name="currentIndex">Index of the current.</param> public ItemChange(ListChangeReason reason, T current, int currentIndex) : this() { Reason = reason; Current = current; CurrentIndex = currentIndex; PreviousIndex = -1; Previous = Optional <T> .None; }
/// <summary> /// Initializes a new instance of the <see cref="Change{TObject, TKey}" /> struct. /// </summary> /// <param name="reason">The reason.</param> /// <param name="current">The current.</param> /// <param name="previous">The previous.</param> /// <param name="currentIndex">Value of the current.</param> /// <param name="previousIndex">Value of the previous.</param> /// <exception cref="ArgumentException">For ChangeReason.Add, a previous value cannot be specified /// or /// For ChangeReason.Change, must supply previous value</exception> /// <exception cref="System.ArgumentException">For ChangeReason.Add, a previous value cannot be specified /// or /// For ChangeReason.Change, must supply previous value</exception> public ItemChange(ListChangeReason reason, T current, Optional <T> previous, int currentIndex = -1, int previousIndex = -1) : this() { Reason = reason; Current = current; Previous = previous; CurrentIndex = currentIndex; PreviousIndex = previousIndex; }
/// <summary> /// Initializes a new instance of the <see cref="Change{TObject, TKey}" /> struct. /// </summary> /// <param name="reason">The reason.</param> /// <param name="current">The current.</param> /// <param name="previous">The previous.</param> /// <param name="currentIndex">Value of the current.</param> /// <param name="previousIndex">Value of the previous.</param> /// <exception cref="ArgumentException"> /// For ChangeReason.Add, a previous value cannot be specified /// or /// For ChangeReason.Change, must supply previous value /// </exception> /// <exception cref="System.ArgumentException">For ChangeReason.Add, a previous value cannot be specified /// or /// For ChangeReason.Change, must supply previous value</exception> public Change(ListChangeReason reason, T current, Optional <T> previous, int currentIndex = -1, int previousIndex = -1) { if (reason == ListChangeReason.Add && previous.HasValue) { throw new ArgumentException("For ChangeReason.Add, a previous value cannot be specified"); } if (reason == ListChangeReason.Replace && !previous.HasValue) { throw new ArgumentException("For ChangeReason.Change, must supply previous value"); } Reason = reason; Item = new ItemChange <T>(Reason, current, previous, currentIndex, previousIndex); }
/// <summary> /// Initializes a new instance of the <see cref="Change{T}"/> class. /// </summary> /// <param name="reason">The reason.</param> /// <param name="items">The items.</param> /// <param name="index">The index.</param> public Change(ListChangeReason reason, IEnumerable<T> items, int index = -1) { if (reason.GetChangeType() == ChangeType.Item) throw new IndexOutOfRangeException("ListChangeReason must be a range type for a range change"); //ignore this case because WhereReasonsAre removes the index //if (reason== ListChangeReason.RemoveRange && index < 0) // throw new UnspecifiedIndexException("ListChangeReason.RemoveRange should not have an index specified index"); Reason = reason; Item = ItemChange<T>.Empty; Range = new RangeChange<T>(items, index); }
public UnifiedChange(ListChangeReason reason, T current, Optional <T> previous) { Reason = reason; Current = current; Previous = previous; }
public UnifiedChange(ListChangeReason reason, T current) : this(reason, current, Optional.None <T>()) { }
public TransformedItem(ListChangeReason reason, T current, Optional <T> previous) { Reason = reason; Current = current; Previous = previous; }
public TransformedItem(ListChangeReason reason, T current) : this(reason, current, Optional.None <T>()) { }
/// <summary> /// Initializes a new instance of the <see cref="Change{T}"/> class. /// </summary> /// <param name="reason">The reason.</param> /// <param name="current">The current.</param> /// <param name="index">The index.</param> public Change(ListChangeReason reason, T current, int index = -1) : this(reason, current, Optional.None <T>(), index, -1) { }