File tree Expand file tree Collapse file tree 4 files changed +62
-2
lines changed
Tests.System.Reactive.ApiApprovals/Api
Tests.System.Reactive/Tests/Disposables Expand file tree Collapse file tree 4 files changed +62
-2
lines changed Original file line number Diff line number Diff line change 1+ // Licensed to the .NET Foundation under one or more agreements.
2+ // The .NET Foundation licenses this file to you under the MIT License.
3+ // See the LICENSE file in the project root for more information.
4+
5+ namespace System . Reactive . Disposables . Fluent ;
6+
7+ /// <summary>
8+ /// Extension methods associated with the IDisposable interface.
9+ /// </summary>
10+ public static class DisposableExtensions
11+ {
12+ /// <summary>
13+ /// Ensures the provided disposable is disposed with the specified <see cref="CompositeDisposable"/>.
14+ /// </summary>
15+ /// <typeparam name="T">
16+ /// The type of the disposable.
17+ /// </typeparam>
18+ /// <param name="item">
19+ /// The disposable we are going to want to be disposed by the CompositeDisposable.
20+ /// </param>
21+ /// <param name="compositeDisposable">
22+ /// The <see cref="CompositeDisposable"/> to which <paramref name="item"/> will be added.
23+ /// </param>
24+ /// <returns>
25+ /// The disposable.
26+ /// </returns>
27+ public static T DisposeWith < T > ( this T item , CompositeDisposable compositeDisposable )
28+ where T : IDisposable
29+ {
30+ if ( compositeDisposable == null )
31+ {
32+ throw new ArgumentNullException ( nameof ( compositeDisposable ) ) ;
33+ }
34+
35+ compositeDisposable . Add ( item ) ;
36+ return item ;
37+ }
38+ }
Original file line number Diff line number Diff line change 154154 </ItemGroup >
155155
156156 <ItemGroup >
157- <None Include =" build\NuGet.Readme.md" Pack =" true" PackagePath =" \readme.md" />
157+ <None Include =" build\NuGet.Readme.md" Pack =" true" PackagePath =" \readme.md" />
158158 <None Include =" build\_._" PackagePath =" build\net6.0;build\net6.0-windows10.0.19041" Pack =" true" />
159159 <None Include =" build\_._" PackagePath =" buildTransitive\net6.0;buildTransitive\net6.0-windows10.0.19041" Pack =" true" />
160160 <None Include =" Linq\QbservableEx.NAry.cs" >
Original file line number Diff line number Diff line change @@ -661,6 +661,14 @@ public static System.Reactive.Disposables.ICancelable Create(params System.IDisp
661661 public static System . Reactive . Disposables . ICancelable Create ( System . IDisposable disposable1 , System . IDisposable disposable2 ) { }
662662 }
663663}
664+ namespace System . Reactive . Disposables . Fluent
665+ {
666+ public static class DisposableExtensions
667+ {
668+ public static T DisposeWith < T > ( this T item , System . Reactive . Disposables . CompositeDisposable compositeDisposable )
669+ where T : System . IDisposable { }
670+ }
671+ }
664672namespace System . Reactive . Joins
665673{
666674 public abstract class Pattern { }
@@ -3190,4 +3198,4 @@ public void Start<TStateMachine>(ref TStateMachine stateMachine)
31903198 where TStateMachine : System . Runtime . CompilerServices . IAsyncStateMachine { }
31913199 public static System . Runtime . CompilerServices . TaskObservableMethodBuilder < T > Create ( ) { }
31923200 }
3193- }
3201+ }
Original file line number Diff line number Diff line change 88using System . Linq ;
99using System . Reactive . Concurrency ;
1010using System . Reactive . Disposables ;
11+ using System . Reactive . Disposables . Fluent ;
1112using System . Threading ;
1213using Microsoft . Reactive . Testing ;
1314using Microsoft . VisualStudio . TestTools . UnitTesting ;
@@ -415,6 +416,19 @@ public void CompositeDisposable_Empty_GetEnumerator()
415416 Assert . False ( composite . GetEnumerator ( ) . MoveNext ( ) ) ;
416417 }
417418
419+ [ TestMethod ]
420+ public void CompositeDisposable_DisposeWith ( )
421+ {
422+ var c = new CompositeDisposable ( ) ;
423+ var d = new BooleanDisposable ( ) ;
424+ d . DisposeWith ( c ) ;
425+ Assert . True ( c . Contains ( d ) ) ;
426+
427+ c . Dispose ( ) ;
428+ Assert . True ( d . IsDisposed ) ;
429+ Assert . True ( c . IsDisposed ) ;
430+ }
431+
418432 [ TestMethod ]
419433 public void CompositeDisposable_NonCollection_Enumerable_Init ( )
420434 {
You can’t perform that action at this time.
0 commit comments