Class CompositeDisposable
Represents a group of disposable resources that are disposed together.
Inherited Members
Namespace: System.Reactive.Disposables
Assembly: System.Reactive.Core.dll
Syntax
public sealed class CompositeDisposable : ICollection<IDisposable>, IEnumerable<IDisposable>, IEnumerable, ICancelable, IDisposable
Constructors
| Improve this Doc View SourceCompositeDisposable()
Initializes a new instance of the CompositeDisposable class with no disposables contained by it initially.
Declaration
public CompositeDisposable()
CompositeDisposable(IEnumerable<IDisposable>)
Initializes a new instance of the CompositeDisposable class from a group of disposables.
Declaration
public CompositeDisposable(IEnumerable<IDisposable> disposables)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDisposable> | disposables | Disposables that will be disposed together. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
CompositeDisposable(IDisposable[])
Initializes a new instance of the CompositeDisposable class from a group of disposables.
Declaration
public CompositeDisposable(params IDisposable[] disposables)
Parameters
Type | Name | Description |
---|---|---|
IDisposable[] | disposables | Disposables that will be disposed together. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
CompositeDisposable(Int32)
Initializes a new instance of the CompositeDisposable class with the specified number of disposables.
Declaration
public CompositeDisposable(int capacity)
Parameters
Type | Name | Description |
---|---|---|
Int32 | capacity | The number of disposables that the new CompositeDisposable can initially store. |
Exceptions
Type | Condition |
---|---|
ArgumentOutOfRangeException |
|
Properties
| Improve this Doc View SourceCount
Gets the number of disposables contained in the CompositeDisposable.
Declaration
public int Count { get; }
Property Value
Type | Description |
---|---|
Int32 |
IsDisposed
Gets a value that indicates whether the object is disposed.
Declaration
public bool IsDisposed { get; }
Property Value
Type | Description |
---|---|
Boolean |
IsReadOnly
Always returns false.
Declaration
public bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
Boolean |
Methods
| Improve this Doc View SourceAdd(IDisposable)
Adds a disposable to the CompositeDisposable or disposes the disposable if the CompositeDisposable is disposed.
Declaration
public void Add(IDisposable item)
Parameters
Type | Name | Description |
---|---|---|
IDisposable | item | Disposable to add. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Clear()
Removes and disposes all disposables from the CompositeDisposable, but does not dispose the CompositeDisposable.
Declaration
public void Clear()
Contains(IDisposable)
Determines whether the CompositeDisposable contains a specific disposable.
Declaration
public bool Contains(IDisposable item)
Parameters
Type | Name | Description |
---|---|---|
IDisposable | item | Disposable to search for. |
Returns
Type | Description |
---|---|
Boolean | true if the disposable was found; otherwise, false. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
CopyTo(IDisposable[], Int32)
Copies the disposables contained in the CompositeDisposable to an array, starting at a particular array index.
Declaration
public void CopyTo(IDisposable[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
IDisposable[] | array | Array to copy the contained disposables to. |
Int32 | arrayIndex | Target index at which to copy the first disposable of the group. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
ArgumentOutOfRangeException |
|
Dispose()
Disposes all disposables in the group and removes them from the group.
Declaration
public void Dispose()
GetEnumerator()
Returns an enumerator that iterates through the CompositeDisposable.
Declaration
public IEnumerator<IDisposable> GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator<IDisposable> | An enumerator to iterate over the disposables. |
Remove(IDisposable)
Removes and disposes the first occurrence of a disposable from the CompositeDisposable.
Declaration
public bool Remove(IDisposable item)
Parameters
Type | Name | Description |
---|---|---|
IDisposable | item | Disposable to remove. |
Returns
Type | Description |
---|---|
Boolean | true if found; false otherwise. |
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
Explicit Interface Implementations
| Improve this Doc View SourceIEnumerable.GetEnumerator()
Returns an enumerator that iterates through the CompositeDisposable.
Declaration
IEnumerator IEnumerable.GetEnumerator()
Returns
Type | Description |
---|---|
IEnumerator | An enumerator to iterate over the disposables. |