1 namespace System.Activities.Presentation.PropertyEditing
4 using System.Collections.Generic;
6 using System.Collections;
7 using System.Collections.Specialized;
8 using System.Activities.Presentation;
11 /// This class encapsulates a collection of PropertyValue instances.
12 /// It is used for properties whose type is a collection.
14 public abstract class PropertyValueCollection : IEnumerable<PropertyValue>, INotifyCollectionChanged
18 /// INotifyCollectionChanged event
20 public event NotifyCollectionChangedEventHandler CollectionChanged;
22 private PropertyValue _parentValue;
25 /// Creates a PropertyValueCollection.
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)
32 if (parentValue == null)
33 throw FxTrace.Exception.ArgumentNull("parentValue");
35 _parentValue = parentValue;
39 /// Gets the parent PropertyValue.
41 public PropertyValue ParentValue { get { return _parentValue; } }
44 /// Indexer that returns a PropertyValue for the given index.
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; }
51 /// Adds an object into the collection.
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);
58 /// Inserts an object into the collection at the specified index
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);
66 /// Removes the object from the collection. The host needs to ensure that
67 /// the PropertyValue is invalid after the object is removed.
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);
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.
77 /// <param name="index">the index of the item to remove</param>
78 public abstract void RemoveAt(int index);
81 /// Gets the number of items in the collection.
83 public abstract int Count { get; }
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.
90 /// <param name="currentIndex"></param>
91 /// <param name="newIndex"></param>
92 public abstract void SetIndex(int currentIndex, int newIndex);
95 /// Returns a strongly typed IEnumerator for the collection of PropertyValues
97 /// <returns></returns>
98 public abstract IEnumerator<PropertyValue> GetEnumerator();
100 IEnumerator IEnumerable.GetEnumerator()
102 return GetEnumerator();
106 /// Used to raise the CollectionChanged event.
108 /// <param name="e"></param>
109 protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
111 if (this.CollectionChanged != null)
112 this.CollectionChanged(this, e ?? new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));