PostSharpAPI ReferencePost­Sharp.​Patterns.​CollectionsAdvisable­Collection<T>
Open sandboxFocus

AdvisableCollection<T> Class

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

Implements
System.Runtime.Serialization.ISerializable
System.Runtime.Serialization.IDeserializationCallback
IList<T>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
IList
IDynamicallyAdvisableCollection
ICollection
System.Collections.IEnumerable
IDynamicallyAdvisable
IQueryInterface
INotifyPropertyChanged
System.Collections.Generic.IReadOnlyList<T>
System.Collections.Generic.IReadOnlyCollection<T>
INotifyCollectionChanged
Namespace: PostSharp.Patterns.Collections
Assembly: PostSharp.Patterns.Common.dll
Syntax
public class AdvisableCollection<T> : DynamicallyAdvisableObject, IDynamicallyAdvisableCollection, IDynamicallyAdvisable, IQueryInterface
Type 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 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.

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(Int32)

Initializes a new instance of the AdvisableCollection<T> class that is empty and has the specified initial capacity.

AdvisableCollection(SerializationInfo, StreamingContext)

Properties

Name Description
Count
IsReadOnly
Item[Int32]

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[], Int32)
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(Int32)

Gets the element at the specified index of the underlying collection.

GetObjectData(SerializationInfo, StreamingContext)
GetRange(Int32, Int32)

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(Int32, T)
InsertItem(Int32, T)

Inserts an element into the underlying collection at the specified index.

InsertItems(Int32, T[])

Inserts elements into the underlying collection at the specified index.

InsertRange(Int32, IEnumerable<T>)

Inserts the elements of a collection into the AdvisableCollection<T> at the specified index.

Move(Int32, Int32)

Moved the element at the specified index to another index.

MoveItem(T, Int32, Int32)

Moves the element at the specified index to another index in the underlying collection.

OnDeserialization(Object)
RaiseEvents()

Raised the events that have been buffered.

Remove(T)
RemoveAt(Int32)
RemoveItem(Int32)

Removes the element at the specified index of the underlying collection.

RemoveItems(Int32, Int32)

Removes the specified number of elements starting at the specified index of the underlying collection.

RemoveRange(Int32, Int32)

Removes a range of elements from the AdvisableCollection<T>.

SetItem(Int32, 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

Event raised when the value of a property of the current object changes.

Explicit Interface Implementations

Name Description
IDynamicallyAdvisableCollection.ItemType