[corlib] Update ValueTuple implementation
[mono.git] / mcs / class / referencesource / System.Activities.Presentation / System.Activities.Presentation / System / Activities / Presentation / Base / Core / PropertyEditing / PropertyValueCollection.cs
1 namespace System.Activities.Presentation.PropertyEditing
2 {
3     using System;
4     using System.Collections.Generic;
5     using System.Text;
6     using System.Collections;
7     using System.Collections.Specialized;
8     using System.Activities.Presentation;
9
10     /// <summary>
11     /// This class encapsulates a collection of PropertyValue instances.  
12     /// It is used for properties whose type is a collection.
13     /// </summary>
14     public abstract class PropertyValueCollection : IEnumerable<PropertyValue>, INotifyCollectionChanged
15     {
16
17         /// <summary>
18         /// INotifyCollectionChanged event
19         /// </summary>
20         public event NotifyCollectionChangedEventHandler CollectionChanged;
21
22         private PropertyValue _parentValue;
23
24         /// <summary>
25         /// Creates a PropertyValueCollection.
26         /// </summary>
27         /// <param name="parentValue">The parent PropertyValue.  This will be the property whose
28         /// Type is a collection</param>
29         /// <exception cref="ArgumentNullException">When parentValue is null</exception>
30         protected PropertyValueCollection(PropertyValue parentValue)
31         {
32             if (parentValue == null)
33                 throw FxTrace.Exception.ArgumentNull("parentValue");
34
35             _parentValue = parentValue;
36         }
37
38         /// <summary>
39         /// Gets the parent PropertyValue.
40         /// </summary>
41         public PropertyValue ParentValue { get { return _parentValue; } }
42
43         /// <summary>
44         /// Indexer that returns a PropertyValue for the given index.
45         /// </summary>
46         /// <param name="index">The index of the item in the collection</param>
47         /// <returns>The PropertyValue at that index</returns>
48         public abstract PropertyValue this[int index] { get; }
49
50         /// <summary>
51         /// Adds an object into the collection.
52         /// </summary>
53         /// <param name="value">The object to add to the collection</param>
54         /// <returns>The PropertyValue for the added object</returns>
55         public abstract PropertyValue Add(object value);
56
57         /// <summary>
58         /// Inserts an object into the collection at the specified index
59         /// </summary>
60         /// <param name="value">The object to add to the collection</param>
61         /// <param name="index">The index of where to add that object</param>
62         /// <returns>A PropertyValue for the added object</returns>
63         public abstract PropertyValue Insert(object value, int index);
64
65         /// <summary>
66         /// Removes the object from the collection.  The host needs to ensure that
67         /// the PropertyValue is invalid after the object is removed.
68         /// </summary>
69         /// <param name="propertyValue">The item to remove from the collection</param>
70         /// <returns>true if successful, otherwise false.</returns>
71         public abstract bool Remove(PropertyValue propertyValue);
72
73         /// <summary>
74         /// Removes the object from the collection at the specified index.  The host needs to ensure that
75         /// the PropertyValue is invalid after the object is removed.
76         /// </summary>
77         /// <param name="index">the index of the item to remove</param>
78         public abstract void RemoveAt(int index);
79
80         /// <summary>
81         /// Gets the number of items in the collection.
82         /// </summary>
83         public abstract int Count { get; }
84
85         /// <summary>
86         /// Used to reorder items in the collection (remove and add will invalidate the PropertyValue)
87         /// when an item is moved to a new index, the items below the new index and the item at the new 
88         /// index will slide down.
89         /// </summary>
90         /// <param name="currentIndex"></param>
91         /// <param name="newIndex"></param>
92         public abstract void SetIndex(int currentIndex, int newIndex);
93
94         /// <summary>
95         /// Returns a strongly typed IEnumerator for the collection of PropertyValues
96         /// </summary>
97         /// <returns></returns>
98         public abstract IEnumerator<PropertyValue> GetEnumerator();
99
100         IEnumerator IEnumerable.GetEnumerator()
101         {
102             return GetEnumerator();
103         }
104
105         /// <summary>
106         /// Used to raise the CollectionChanged event.
107         /// </summary>
108         /// <param name="e"></param>
109         protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
110         {
111             if (this.CollectionChanged != null)
112                 this.CollectionChanged(this, e ?? new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));
113         }
114     }
115 }