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 154
154
</ItemGroup >
155
155
156
156
<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" />
158
158
<None Include =" build\_._" PackagePath =" build\net6.0;build\net6.0-windows10.0.19041" Pack =" true" />
159
159
<None Include =" build\_._" PackagePath =" buildTransitive\net6.0;buildTransitive\net6.0-windows10.0.19041" Pack =" true" />
160
160
<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
661
661
public static System . Reactive . Disposables . ICancelable Create ( System . IDisposable disposable1 , System . IDisposable disposable2 ) { }
662
662
}
663
663
}
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
+ }
664
672
namespace System . Reactive . Joins
665
673
{
666
674
public abstract class Pattern { }
@@ -3190,4 +3198,4 @@ public void Start<TStateMachine>(ref TStateMachine stateMachine)
3190
3198
where TStateMachine : System . Runtime . CompilerServices . IAsyncStateMachine { }
3191
3199
public static System . Runtime . CompilerServices . TaskObservableMethodBuilder < T > Create ( ) { }
3192
3200
}
3193
- }
3201
+ }
Original file line number Diff line number Diff line change 8
8
using System . Linq ;
9
9
using System . Reactive . Concurrency ;
10
10
using System . Reactive . Disposables ;
11
+ using System . Reactive . Disposables . Fluent ;
11
12
using System . Threading ;
12
13
using Microsoft . Reactive . Testing ;
13
14
using Microsoft . VisualStudio . TestTools . UnitTesting ;
@@ -415,6 +416,19 @@ public void CompositeDisposable_Empty_GetEnumerator()
415
416
Assert . False ( composite . GetEnumerator ( ) . MoveNext ( ) ) ;
416
417
}
417
418
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
+
418
432
[ TestMethod ]
419
433
public void CompositeDisposable_NonCollection_Enumerable_Init ( )
420
434
{
You can’t perform that action at this time.
0 commit comments