From 18ec83493c8110cd821b03337a6d09c5f58bc2b6 Mon Sep 17 00:00:00 2001 From: Steven Kirk Date: Sun, 9 Aug 2015 21:08:08 +0200 Subject: [PATCH] Documented PerspexList. --- Perspex.Base/Collections/PerspexList.cs | 127 ++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 7 deletions(-) diff --git a/Perspex.Base/Collections/PerspexList.cs b/Perspex.Base/Collections/PerspexList.cs index 1c24a52db7..c7a2299aa9 100644 --- a/Perspex.Base/Collections/PerspexList.cs +++ b/Perspex.Base/Collections/PerspexList.cs @@ -27,60 +27,91 @@ namespace Perspex.Collections { private List inner; + /// + /// Initializes a new instance of the class. + /// public PerspexList() : this(Enumerable.Empty()) { } + /// + /// Initializes a new instance of the class. + /// + /// The initial items for the collection. public PerspexList(IEnumerable items) { this.inner = new List(items); } + /// + /// Initializes a new instance of the class. + /// + /// The initial items for the collection. public PerspexList(params T[] items) { this.inner = new List(items); } + /// + /// Raised when a change is made to the collection's items. + /// public event NotifyCollectionChangedEventHandler CollectionChanged; + /// + /// Raised when a property on the collection changes. + /// public event PropertyChangedEventHandler PropertyChanged; + /// + /// Gets the number of items in the collection. + /// public int Count { get { return this.inner.Count; } } - public bool IsReadOnly - { - get { return false; } - } - + /// bool IList.IsFixedSize { get { return false; } - } + } + /// bool IList.IsReadOnly { get { return false; } } + /// int ICollection.Count { get { return this.inner.Count; } } + /// bool ICollection.IsSynchronized { get { return false; } } + /// object ICollection.SyncRoot { get { return null; } } + /// + bool ICollection.IsReadOnly + { + get { return false; } + } + + /// + /// Gets or sets the item at the specified index. + /// + /// The index. + /// The item. public T this[int index] { get @@ -104,13 +135,21 @@ namespace Perspex.Collections } } + /// + /// Gets or sets the item at the specified index. + /// + /// The index. + /// The item. object IList.this[int index] { get { return this[index]; } - set { this[index] = (T)value; } } + /// + /// Adds an item to the collection. + /// + /// The item. public void Add(T item) { int index = this.inner.Count; @@ -118,6 +157,10 @@ namespace Perspex.Collections this.NotifyAdd(new[] { item }, index); } + /// + /// Adds multiple items to the collection. + /// + /// The items. public void AddRange(IEnumerable items) { Contract.Requires(items != null); @@ -127,6 +170,9 @@ namespace Perspex.Collections this.NotifyAdd((items as IList) ?? items.ToList(), index); } + /// + /// Removes all items from the collection. + /// public void Clear() { var old = this.inner; @@ -134,32 +180,63 @@ namespace Perspex.Collections this.NotifyRemove(old, 0); } + /// + /// Tests if the collection contains the specified item. + /// + /// The item. + /// True if the collection contains the item; otherwise false. public bool Contains(T item) { return this.inner.Contains(item); } + /// + /// Copies the collection's contents to an array. + /// + /// The array. + /// The first index of the array to copy to. public void CopyTo(T[] array, int arrayIndex) { this.inner.CopyTo(array, arrayIndex); } + /// + /// Returns an enumerator that enumerates the items in the collection. + /// + /// An . public IEnumerator GetEnumerator() { return this.inner.GetEnumerator(); } + /// + /// Gets the index of the specified item in the collection. + /// + /// The item. + /// + /// The index of the item or -1 if the item is not contained in the collection. + /// public int IndexOf(T item) { return this.inner.IndexOf(item); } + /// + /// Inserts an item at the specified index. + /// + /// The index. + /// The item. public void Insert(int index, T item) { this.inner.Insert(index, item); this.NotifyAdd(new[] { item }, index); } + /// + /// Inserts multiple items at the specified index. + /// + /// The index. + /// The items. public void InsertRange(int index, IEnumerable items) { Contract.Requires(items != null); @@ -168,6 +245,11 @@ namespace Perspex.Collections this.NotifyAdd((items as IList) ?? items.ToList(), index); } + /// + /// Removes an item from the collection. + /// + /// The item. + /// True if the item was found and removed, otherwise false. public bool Remove(T item) { int index = this.inner.IndexOf(item); @@ -182,6 +264,10 @@ namespace Perspex.Collections return false; } + /// + /// Removes multiple items from the collection. + /// + /// The items. public void RemoveAll(IEnumerable items) { Contract.Requires(items != null); @@ -195,6 +281,10 @@ namespace Perspex.Collections } } + /// + /// Removes the item at the specified index. + /// + /// The index. public void RemoveAt(int index) { T item = this.inner[index]; @@ -202,6 +292,7 @@ namespace Perspex.Collections this.NotifyRemove(new[] { item }, index); } + /// int IList.Add(object value) { int index = this.Count; @@ -209,46 +300,59 @@ namespace Perspex.Collections return index; } + /// bool IList.Contains(object value) { return this.Contains((T)value); } + /// void IList.Clear() { this.Clear(); } + /// int IList.IndexOf(object value) { return this.IndexOf((T)value); } + /// void IList.Insert(int index, object value) { this.Insert(index, (T)value); } + /// void IList.Remove(object value) { this.Remove((T)value); } + /// void IList.RemoveAt(int index) { this.RemoveAt(index); } + /// void ICollection.CopyTo(Array array, int index) { this.inner.CopyTo((T[])array, index); } + /// IEnumerator IEnumerable.GetEnumerator() { return this.inner.GetEnumerator(); } + /// + /// Raises the event with an add action. + /// + /// The items that were added. + /// The starting index. private void NotifyAdd(IList t, int index) { if (this.CollectionChanged != null) @@ -260,6 +364,10 @@ namespace Perspex.Collections this.NotifyCountChanged(); } + /// + /// Raises the event when the property + /// changes. + /// private void NotifyCountChanged() { if (this.PropertyChanged != null) @@ -268,6 +376,11 @@ namespace Perspex.Collections } } + /// + /// Raises the event with a remove action. + /// + /// The items that were removed. + /// The starting index. private void NotifyRemove(IList t, int index) { if (this.CollectionChanged != null)