Class DisposableExtensions
- Namespace
- CarinaStudio
- Assembly
- CarinaStudio.AppBase.Core.dll
Extensions for IDisposable.
public static class DisposableExtensions
- Inheritance
-
DisposableExtensions
- Inherited Members
Methods
DisposeAndReturnNullAsync<T>(T?)
Call Dispose() and return null.
public static Task<T?> DisposeAndReturnNullAsync<T>(this T? disposable) where T : class, IAsyncDisposable
Parameters
disposable
T
Returns
- Task<T>
Null.
Type Parameters
T
Type which implements IDisposable.
DisposeAndReturnNull<T>(T?)
Call Dispose() and return null.
public static T? DisposeAndReturnNull<T>(this T? disposable) where T : class, IDisposable
Parameters
disposable
T
Returns
- T
Null.
Type Parameters
T
Type which implements IDisposable.
ExchangeAsync<T, R>(T, Func<Task<R?>>)
Exchange the source IDisposable with another one asynchronously.
public static Task<R?> ExchangeAsync<T, R>(this T source, Func<Task<R?>> func) where T : class, IDisposable where R : class, IDisposable
Parameters
source
TSource IDisposable.
func
Func<Task<R>>Exchanging function.
Returns
- Task<R>
Task of exchanging IDisposable.
Type Parameters
T
Type of source IDisposable.
R
Type of result IDisposable.
ExchangeAsync<T, R>(T, Func<T, Task<R?>>)
Exchange the source IDisposable with another one asynchronously.
public static Task<R?> ExchangeAsync<T, R>(this T source, Func<T, Task<R?>> func) where T : class, IDisposable where R : class, IDisposable
Parameters
source
TSource IDisposable.
func
Func<T, Task<R>>Exchanging function.
Returns
- Task<R>
Task of exchanging IDisposable.
Type Parameters
T
Type of source IDisposable.
R
Type of result IDisposable.
Exchange<T, R>(T, Func<T, R?>)
Exchange the source IDisposable with another one.
public static R? Exchange<T, R>(this T source, Func<T, R?> func) where T : class, IDisposable where R : class, IDisposable
Parameters
source
TSource IDisposable.
func
Func<T, R>Exchanging function.
Returns
- R
Exchanged IDisposable.
Type Parameters
T
Type of source IDisposable.
R
Type of result IDisposable.
Exchange<T, R>(T, Func<R?>)
Exchange the source IDisposable with another one.
public static R? Exchange<T, R>(this T source, Func<R?> func) where T : class, IDisposable where R : class, IDisposable
Parameters
source
TSource IDisposable.
func
Func<R>Exchanging function.
Returns
- R
Exchanged IDisposable.
Type Parameters
T
Type of source IDisposable.
R
Type of result IDisposable.
SetupAsync<T>(T, Func<Task>)
Setup given instance of IDisposable asynchronously and make sure that Dispose() will be called if exception occurs during setup.
public static Task<T> SetupAsync<T>(this T obj, Func<Task> action) where T : IDisposable
Parameters
obj
TIDisposable to setup.
action
Func<Task>Action to setup.
Returns
- Task<T>
Task of setup. The result is instance of IDisposable.
Type Parameters
T
Type of IDisposable to setup.
SetupAsync<T>(T, Func<T, Task>)
Setup given instance of IDisposable asynchronously and make sure that Dispose() will be called if exception occurs during setup.
public static Task<T> SetupAsync<T>(this T obj, Func<T, Task> action) where T : IDisposable
Parameters
obj
TIDisposable to setup.
action
Func<T, Task>Action to setup.
Returns
- Task<T>
Task of setup. The result is instance of IDisposable.
Type Parameters
T
Type of IDisposable to setup.
Setup<T>(T, Action)
Setup given instance of IDisposable and make sure that Dispose() will be called if exception occurs during setup.
public static T Setup<T>(this T obj, Action action) where T : IDisposable
Parameters
obj
TIDisposable to setup.
action
ActionAction to setup.
Returns
- T
The instance of IDisposable.
Type Parameters
T
Type of IDisposable to setup.
Setup<T>(T, Action<T>)
Setup given instance of IDisposable and make sure that Dispose() will be called if exception occurs during setup.
public static T Setup<T>(this T obj, Action<T> action) where T : IDisposable
Parameters
obj
TIDisposable to setup.
action
Action<T>Action to setup.
Returns
- T
The instance of IDisposable.
Type Parameters
T
Type of IDisposable to setup.
UseAsync<T>(T, Func<T, Task>)
Use the given IDisposable to perform action asynchronously then dispose it before returning from method.
public static Task UseAsync<T>(this T disposable, Func<T, Task> action) where T : IDisposable
Parameters
Returns
- Task
Task of asynchronous action.
Type Parameters
T
Type which implements IDisposable.
UseAsync<T, R>(T, Func<T, Task<R>>)
Use the given IDisposable to generate value asynchronously then dispose it before returning from method.
public static Task<R> UseAsync<T, R>(this T disposable, Func<T, Task<R>> func) where T : IDisposable
Parameters
Returns
- Task<R>
Task of generating value.
Type Parameters
T
Type which implements IDisposable.
R
Type of generated value.
Use<T>(T, Action<T>)
Use the given IDisposable to perform action then dispose it before returning from method.
public static void Use<T>(this T disposable, Action<T> action) where T : IDisposable
Parameters
disposable
Taction
Action<T>Action to perform.
Type Parameters
T
Type which implements IDisposable.
Use<T, R>(T, RefOutFunc<T, R>)
Use the given IDisposable to generate reference to value then dispose it before returning from method.
public static ref R Use<T, R>(this T disposable, RefOutFunc<T, R> func) where T : IDisposable
Parameters
disposable
Tfunc
RefOutFunc<T, R>Using function.
Returns
- R
Generated reference to value.
Type Parameters
T
Type which implements IDisposable.
R
Type of generated reference to value.
Use<T, R>(T, Func<T, R>)
Use the given IDisposable to generate value then dispose it before returning from method.
public static R Use<T, R>(this T disposable, Func<T, R> func) where T : IDisposable
Parameters
disposable
Tfunc
Func<T, R>Using function.
Returns
- R
Generated value.
Type Parameters
T
Type which implements IDisposable.
R
Type of generated value.