A collection type similar to Collection<T> into which advices can be injected dynamically.
Inheritance
Namespace: PostSharp.Patterns.Collections
Assembly: PostSharp.Patterns.Common.dll
Syntax
public class AdvisableCollection<T> : DynamicallyAdvisableObject, ISerializable, IDeserializationCallback, IList<T>, ICollection<T>, IList, IDynamicallyAdvisableCollection, ICollection, IDynamicallyAdvisable, IQueryInterface, INotifyPropertyChanged, IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChangedType Parameters
| Name | Description |
|---|---|
| T | The type of elements in the collection. |
Remarks
The API of this class is compatible with the Collection<T> class. It provides some additions, but preserves the same design and naming conventions.
Classes that derive from AdvisableCollection<T> can add functionalities by overriding protected methods or by defining new public methods.
New public methods wrap their logic in a call of the ExecuteWithAdvices<TResult, TAction>(ObjectAccessLevel, ref TAction) method,
which applies boundary aspects. Public methods can access the data structure through protected methods, which have a name ending in Item, for example SetItem(int, T).
Public methods should not use other public methods of the class, because this may cause inconsistent invocation of advices and performance issues. Events (PropertyChanged and CollectionChanged)
are buffered. Public methods must invoke RaiseEvents() to raise buffered events.
Use this class instead of an array, List<T>, Collection<T> or ObservableCollection<T> in the child properties of classes that use patterns such as Aggregatable, Recordable or threading models. These patterns cannot extend standard collections, so they inject their behavior into advisable collections at run time instead. Because the interfaces that they add are not known to the compiler, use QueryInterface<T>(object, bool) instead of a cast to access them.
A threading model synchronizes an advisable collection only after the collection is assigned to a child property of an object that has a threading model. The collection then uses the concurrency controller of this object. Before that, the collection is not thread-safe: do not access it from several threads at the same time, and do not modify it while another thread assigns it to its parent.
Constructors
| Name | Description |
|---|---|
| AdvisableCollection() | Initializes a new instance of the AdvisableCollection<T> class that is empty and has the default initial capacity. |
| AdvisableCollection(IEnumerable<T>) | Initializes a new instance of the AdvisableCollection<T> class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied. |
| AdvisableCollection(int) | Initializes a new instance of the AdvisableCollection<T> class that is empty and has the specified initial capacity. |
Properties
| Name | Description |
|---|---|
| Count | |
| IsReadOnly | |
| this[int] |
Methods
| Name | Description |
|---|---|
| Add(T) | |
| AddRange(IEnumerable<T>) | Adds the elements of the specified collection to the end of the AdvisableCollection<T>. |
| Clear() | |
| ClearItems() | Removes all elements from the underlying collection. |
| Contains(T) | |
| CopyTo(T[], int) | |
| GetAdviceEnumerator() | Gets an AdviceEnumerator<T> for the ICollectionDynamicAdvice<T> interface. |
| GetCount() | Gets the number of elements in the underlying collection. |
| GetEnumerator() | Returns an enumerator that iterates through the AdvisableCollection<T>. |
| GetItem(int) | Gets the element at the specified index of the underlying collection. |
| GetObjectData(SerializationInfo, StreamingContext) | |
| GetRange(int, int) | Creates a shallow copy of a range of elements in the source AdvisableCollection<T>. |
| IndexOf(T) | |
| IndexOfItem(T) | Searches for the specified object and returns the zero-based index of the first occurrence within the entire underlying collection. |
| Insert(int, T) | |
| InsertItem(int, T) | Inserts an element into the underlying collection at the specified index. |
| InsertItems(int, T[]) | Inserts elements into the underlying collection at the specified index. |
| InsertRange(int, IEnumerable<T>) | Inserts the elements of a collection into the AdvisableCollection<T> at the specified index. |
| Move(int, int) | Moves the element at the specified index to another index. |
| MoveItem(T, int, int) | Moves the element at the specified index to another index in the underlying collection. |
| OnDeserialization(object) | |
| RaiseEvents() | Raises the events that have been buffered. |
| Remove(T) | |
| RemoveAt(int) | |
| RemoveItem(int) | Removes the element at the specified index of the underlying collection. |
| RemoveItems(int, int) | Removes the specified number of elements starting at the specified index of the underlying collection. |
| RemoveRange(int, int) | Removes a range of elements from the AdvisableCollection<T>. |
| SetItem(int, T) | Replaces the element at the specified index of the underlying collection. |
| ToArray() | Creates an array from the current AdvisableCollection<T>. |
Events
| Name | Description |
|---|---|
| CollectionChanged | |
| PropertyChanged | Occurs when the value of a property of the current object changes. |