Post­Sharp Documentation / API Reference / Post­Sharp.​Patterns.​Collections Namespace / Advisable­Collection(T) Class

AdvisableCollection<T> Class

A collection type similar to Collection<T> into which advices can be injected dynamically.
Inheritance Hierarchy

Namespace:  PostSharp.Patterns.Collections
Assembly:  PostSharp.Patterns.Common (in PostSharp.Patterns.Common.dll) Version: 5.0.38.0 (5.0.38.0)
Syntax
C#
[SerializableAttribute]
public class AdvisableCollection<T> : DynamicallyAdvisableObject, 
	IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, 
	ICollection, IQueryInterface, INotifyPropertyChanged, INotifyCollectionChanged

Type Parameters

T
The type of elements in the collection

The AdvisableCollection<T> type exposes the following members.

Properties
  NameDescription
Public propertyCount
Gets the number of elements contained in the ICollection<T>.
Public propertyIsReadOnly
Gets a value indicating whether the ICollection<T> is read-only.
Public propertyItem
Gets or sets the element at the specified index.
Methods
  NameDescription
Public methodAdd
Adds an item to the ICollection<T>.
Public methodAddRange
Adds the elements of the specified collection to the end of the AdvisableCollection<T>.
Public methodClear
Removes all items from the ICollection<T>.
Protected methodClearItems
Removes all elements from the underlying collection.
Public methodContains
Determines whether the ICollection<T> contains a specific value.
Public methodCopyTo
Copies the elements of the ICollection<T> to an Array, starting at a particular Array index.
Protected methodExecuteWithAdvices<TResult, TAction>
Executes an action wrapped by all custom advices added to the current object.
(Inherited from DynamicallyAdvisableObject.)
Protected methodGetCount
Gets the number of elements in the underlying collection.
Public methodGetEnumerator
Returns an enumerator that iterates through the AdvisableCollection<T>.
Protected methodGetItem
Gets the element at the specified index of the underlying collection.
Public methodGetObjectData
Populates a SerializationInfo with the data needed to serialize the target object.
(Overrides DynamicallyAdvisableObject.GetObjectData(SerializationInfo, StreamingContext).)
Public methodGetRange
Creates a shallow copy of a range of elements in the source AdvisableCollection<T>.
Public methodIndexOf
Determines the index of a specific item in the IList<T>.
Protected methodIndexOfItem
Searches for the specified object and returns the zero-based index of the first occurrence within the entire underlying collection.
Public methodInsert
Inserts an item to the IList<T> at the specified index.
Protected methodInsertItem
Inserts an element into the underlying collection at the specified index.
Protected methodInsertItems
Inserts elements into the underlying collection at the specified index.
Public methodInsertRange
Inserts the elements of a collection into the AdvisableCollection<T> at the specified index.
Public methodMove
Moved the element at the specified index to another index.
Protected methodMoveItem
Moves the element at the specified index to another index in the underlying collection.
Public methodOnDeserialization
Runs when the entire object graph has been deserialized.
(Overrides DynamicallyAdvisableObject.OnDeserialization(Object).)
Protected methodRaiseEvents
Raised the events that have been buffered.
Public methodRemove
Removes the first occurrence of a specific object from the ICollection<T>.
Public methodRemoveAt
Removes the IList<T> item at the specified index.
Protected methodRemoveItem
Removes the element at the specified index of the underlying collection.
Protected methodRemoveItems
Removes the specified number of elements starting at the specified index of the underlying collection.
Public methodRemoveRange
Removes a range of elements from the AdvisableCollection<T>.
Protected methodSetItem
Replaces the element at the specified index of the underlying collection.
Public methodToArray
Creates an array from the current AdvisableCollection<T>.
Events
  NameDescription
Public eventCollectionChanged
Occurs when the collection changes.
Public eventPropertyChanged
Event raised when the value of a property of the current object changes.
Extension Methods
  NameDescription
Public Extension MethodQueryInterface<T>
Gets the implementation of a specified interface for the specified object.
(Defined by QueryInterfaceExtensions.)
Public Extension MethodToAdvisableCollection<T>
Converts an IEnumerable<T> into an AdvisableCollection<T>.
(Defined by Extensions.)
Public Extension MethodToAdvisableDictionary<T, TKey, TValue>
Converts an IEnumerable<T> into a AdvisableDictionary<TKey, TValue> given a method returning the item key and a method returning the item value.
(Defined by Extensions.)
Public Extension MethodToAdvisableHashSet<T>
Converts an IEnumerable<T> into an AdvisableHashSet<T>.
(Defined by Extensions.)
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, TAction) method, which applies boundary aspects. Public methods can access the data structure thanks to protected methods, which have a name ending in Item, for instance SetItem(Int32, T). Public methods should not use other public methods of the class, as it may cause inconsistent invocation of advises and performance issues. Events (PropertyChanged and CollectionChanged( are buffered. Public methods must invoke RaiseEvents() to raise buffered events.

See Also