|
@@ -2,6 +2,7 @@
|
|
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
|
|
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
|
|
// See the LICENSE file in the project root for more information.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
+using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
|
|
|
@@ -45,8 +46,8 @@ namespace System.Reactive.Disposables
|
|
/// Initializes a new instance of the <see cref="CompositeDisposable"/> class from a group of disposables.
|
|
/// Initializes a new instance of the <see cref="CompositeDisposable"/> class from a group of disposables.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="disposables">Disposables that will be disposed together.</param>
|
|
/// <param name="disposables">Disposables that will be disposed together.</param>
|
|
- /// <exception cref="ArgumentNullException"><paramref name="disposables"/> is null.</exception>
|
|
|
|
- /// <exception cref="ArgumentException">Any of the disposables in the <paramref name="disposables"/> collection is null.</exception>
|
|
|
|
|
|
+ /// <exception cref="ArgumentNullException"><paramref name="disposables"/> is <c>null</c>.</exception>
|
|
|
|
+ /// <exception cref="ArgumentException">Any of the disposables in the <paramref name="disposables"/> collection is <c>null</c>.</exception>
|
|
public CompositeDisposable(params IDisposable[] disposables)
|
|
public CompositeDisposable(params IDisposable[] disposables)
|
|
: this((IEnumerable<IDisposable>)disposables)
|
|
: this((IEnumerable<IDisposable>)disposables)
|
|
{
|
|
{
|
|
@@ -56,21 +57,21 @@ namespace System.Reactive.Disposables
|
|
/// Initializes a new instance of the <see cref="CompositeDisposable"/> class from a group of disposables.
|
|
/// Initializes a new instance of the <see cref="CompositeDisposable"/> class from a group of disposables.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="disposables">Disposables that will be disposed together.</param>
|
|
/// <param name="disposables">Disposables that will be disposed together.</param>
|
|
- /// <exception cref="ArgumentNullException"><paramref name="disposables"/> is null.</exception>
|
|
|
|
- /// <exception cref="ArgumentException">Any of the disposables in the <paramref name="disposables"/> collection is null.</exception>
|
|
|
|
|
|
+ /// <exception cref="ArgumentNullException"><paramref name="disposables"/> is <c>null</c>.</exception>
|
|
|
|
+ /// <exception cref="ArgumentException">Any of the disposables in the <paramref name="disposables"/> collection is <c>null</c>.</exception>
|
|
public CompositeDisposable(IEnumerable<IDisposable> disposables)
|
|
public CompositeDisposable(IEnumerable<IDisposable> disposables)
|
|
{
|
|
{
|
|
if (disposables == null)
|
|
if (disposables == null)
|
|
throw new ArgumentNullException(nameof(disposables));
|
|
throw new ArgumentNullException(nameof(disposables));
|
|
|
|
|
|
_disposables = new List<IDisposable>(disposables);
|
|
_disposables = new List<IDisposable>(disposables);
|
|
-
|
|
|
|
|
|
+
|
|
//
|
|
//
|
|
// Doing this on the list to avoid duplicate enumeration of disposables.
|
|
// Doing this on the list to avoid duplicate enumeration of disposables.
|
|
//
|
|
//
|
|
if (_disposables.Contains(null))
|
|
if (_disposables.Contains(null))
|
|
throw new ArgumentException(Strings_Core.DISPOSABLES_CANT_CONTAIN_NULL, nameof(disposables));
|
|
throw new ArgumentException(Strings_Core.DISPOSABLES_CANT_CONTAIN_NULL, nameof(disposables));
|
|
-
|
|
|
|
|
|
+
|
|
_count = _disposables.Count;
|
|
_count = _disposables.Count;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -83,7 +84,7 @@ namespace System.Reactive.Disposables
|
|
/// Adds a disposable to the <see cref="CompositeDisposable"/> or disposes the disposable if the <see cref="CompositeDisposable"/> is disposed.
|
|
/// Adds a disposable to the <see cref="CompositeDisposable"/> or disposes the disposable if the <see cref="CompositeDisposable"/> is disposed.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="item">Disposable to add.</param>
|
|
/// <param name="item">Disposable to add.</param>
|
|
- /// <exception cref="ArgumentNullException"><paramref name="item"/> is null.</exception>
|
|
|
|
|
|
+ /// <exception cref="ArgumentNullException"><paramref name="item"/> is <c>null</c>.</exception>
|
|
public void Add(IDisposable item)
|
|
public void Add(IDisposable item)
|
|
{
|
|
{
|
|
if (item == null)
|
|
if (item == null)
|
|
@@ -99,8 +100,11 @@ namespace System.Reactive.Disposables
|
|
_count++;
|
|
_count++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
if (shouldDispose)
|
|
if (shouldDispose)
|
|
|
|
+ {
|
|
item.Dispose();
|
|
item.Dispose();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -108,7 +112,7 @@ namespace System.Reactive.Disposables
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="item">Disposable to remove.</param>
|
|
/// <param name="item">Disposable to remove.</param>
|
|
/// <returns>true if found; false otherwise.</returns>
|
|
/// <returns>true if found; false otherwise.</returns>
|
|
- /// <exception cref="ArgumentNullException"><paramref name="item"/> is null.</exception>
|
|
|
|
|
|
+ /// <exception cref="ArgumentNullException"><paramref name="item"/> is <c>null</c>.</exception>
|
|
public bool Remove(IDisposable item)
|
|
public bool Remove(IDisposable item)
|
|
{
|
|
{
|
|
if (item == null)
|
|
if (item == null)
|
|
@@ -140,15 +144,21 @@ namespace System.Reactive.Disposables
|
|
_disposables = new List<IDisposable>(_disposables.Capacity / 2);
|
|
_disposables = new List<IDisposable>(_disposables.Capacity / 2);
|
|
|
|
|
|
foreach (var d in old)
|
|
foreach (var d in old)
|
|
|
|
+ {
|
|
if (d != null)
|
|
if (d != null)
|
|
|
|
+ {
|
|
_disposables.Add(d);
|
|
_disposables.Add(d);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
if (shouldDispose)
|
|
if (shouldDispose)
|
|
|
|
+ {
|
|
item.Dispose();
|
|
item.Dispose();
|
|
|
|
+ }
|
|
|
|
|
|
return shouldDispose;
|
|
return shouldDispose;
|
|
}
|
|
}
|
|
@@ -173,8 +183,9 @@ namespace System.Reactive.Disposables
|
|
if (currentDisposables != null)
|
|
if (currentDisposables != null)
|
|
{
|
|
{
|
|
foreach (var d in currentDisposables)
|
|
foreach (var d in currentDisposables)
|
|
- if (d != null)
|
|
|
|
- d.Dispose();
|
|
|
|
|
|
+ {
|
|
|
|
+ d?.Dispose();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -192,8 +203,9 @@ namespace System.Reactive.Disposables
|
|
}
|
|
}
|
|
|
|
|
|
foreach (var d in currentDisposables)
|
|
foreach (var d in currentDisposables)
|
|
- if (d != null)
|
|
|
|
- d.Dispose();
|
|
|
|
|
|
+ {
|
|
|
|
+ d?.Dispose();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -201,7 +213,7 @@ namespace System.Reactive.Disposables
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="item">Disposable to search for.</param>
|
|
/// <param name="item">Disposable to search for.</param>
|
|
/// <returns>true if the disposable was found; otherwise, false.</returns>
|
|
/// <returns>true if the disposable was found; otherwise, false.</returns>
|
|
- /// <exception cref="ArgumentNullException"><paramref name="item"/> is null.</exception>
|
|
|
|
|
|
+ /// <exception cref="ArgumentNullException"><paramref name="item"/> is <c>null</c>.</exception>
|
|
public bool Contains(IDisposable item)
|
|
public bool Contains(IDisposable item)
|
|
{
|
|
{
|
|
if (item == null)
|
|
if (item == null)
|
|
@@ -218,7 +230,7 @@ namespace System.Reactive.Disposables
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <param name="array">Array to copy the contained disposables to.</param>
|
|
/// <param name="array">Array to copy the contained disposables to.</param>
|
|
/// <param name="arrayIndex">Target index at which to copy the first disposable of the group.</param>
|
|
/// <param name="arrayIndex">Target index at which to copy the first disposable of the group.</param>
|
|
- /// <exception cref="ArgumentNullException"><paramref name="array"/> is null.</exception>
|
|
|
|
|
|
+ /// <exception cref="ArgumentNullException"><paramref name="array"/> is <c>null</c>.</exception>
|
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than zero. -or - <paramref name="arrayIndex"/> is larger than or equal to the array length.</exception>
|
|
/// <exception cref="ArgumentOutOfRangeException"><paramref name="arrayIndex"/> is less than zero. -or - <paramref name="arrayIndex"/> is larger than or equal to the array length.</exception>
|
|
public void CopyTo(IDisposable[] array, int arrayIndex)
|
|
public void CopyTo(IDisposable[] array, int arrayIndex)
|
|
{
|
|
{
|
|
@@ -258,7 +270,7 @@ namespace System.Reactive.Disposables
|
|
/// Returns an enumerator that iterates through the <see cref="CompositeDisposable"/>.
|
|
/// Returns an enumerator that iterates through the <see cref="CompositeDisposable"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
/// <returns>An enumerator to iterate over the disposables.</returns>
|
|
/// <returns>An enumerator to iterate over the disposables.</returns>
|
|
- System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator();
|
|
|
|
|
|
+ IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets a value that indicates whether the object is disposed.
|
|
/// Gets a value that indicates whether the object is disposed.
|