Skip to content

Commit

Permalink
Merge pull request #1 from polyadic/improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bash authored Mar 20, 2023
2 parents 08b49cb + 8be4f9d commit c03d845
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<PropertyGroup>
<Version>0.1.0</Version>
<Version>0.2.0</Version>
</PropertyGroup>
<PropertyGroup Label="Shared NuGet Metadata">
<Authors>Polyadic</Authors>
Expand Down
1 change: 1 addition & 0 deletions Dispownership.sln
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.gitattributes = .gitattributes
.gitignore = .gitignore
readme.md = readme.md
changelog.md = changelog.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build Config", "Build Config", "{688F10E7-1CEB-412E-A9A8-8BD16F2BDED5}"
Expand Down
10 changes: 8 additions & 2 deletions Dispownership/AsyncDisposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,26 @@ public static AsyncDisposable<TDisposable> Owned<TDisposable>(TDisposable value)
where TDisposable : IAsyncDisposable
=> new(value, hasOwnership: true);

/// <summary>Creates a owned wrapper around a disposable i.e. the disposable will be disposed when the wrapper is disposed.</summary>
/// <remarks>This overload is useful to communicate the ownership to analyzers such as <c>IDisposableAnalyzers</c>.</remarks>
public static AsyncDisposable<TDisposable> Owned<TDisposable>(Func<TDisposable> createValue)
where TDisposable : IAsyncDisposable
=> Owned(createValue());

/// <summary>Creates a borrowing wrapper around a disposable i.e. the disposable will not be disposed when the wrapper is disposed.</summary>
public static AsyncDisposable<TDisposable> Borrowed<TDisposable>(TDisposable value)
where TDisposable : IAsyncDisposable
=> new(value, hasOwnership: false);
}

/// <summary>A wrapper around an <see cref="IAsyncDisposable"/> that either owns or borrows the value.
/// Use <see cref="AsyncDisposable.Owned{TDisposable}"/> or <see cref="AsyncDisposable.Borrowed{TDisposable}"/> to create an instance of this wrapper.</summary>
/// Use <see cref="AsyncDisposable.Owned{TDisposable}(TDisposable)"/> or <see cref="AsyncDisposable.Borrowed{TDisposable}"/> to create an instance of this wrapper.</summary>
#if DISPOWNERSHIP_VISIBILITY_PUBLIC
public
#else
internal
#endif
struct AsyncDisposable<TDisposable> : IAsyncDisposable
sealed class AsyncDisposable<TDisposable> : IAsyncDisposable
where TDisposable : IAsyncDisposable
{
private readonly TDisposable _inner;
Expand Down
10 changes: 8 additions & 2 deletions Dispownership/Disposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,26 @@ public static Disposable<TDisposable> Owned<TDisposable>(TDisposable value)
where TDisposable : IDisposable
=> new(value, hasOwnership: true);

/// <summary>Creates a owned wrapper around a disposable i.e. the disposable will be disposed when the wrapper is disposed.</summary>
/// <remarks>This overload is useful to communicate the ownership to analyzers such as <c>IDisposableAnalyzers</c>.</remarks>
public static Disposable<TDisposable> Owned<TDisposable>(Func<TDisposable> createValue)
where TDisposable : IDisposable
=> Owned(createValue());

/// <summary>Creates a borrowing wrapper around a disposable i.e. the disposable will not be disposed when the wrapper is disposed.</summary>
public static Disposable<TDisposable> Borrowed<TDisposable>(TDisposable value)
where TDisposable : IDisposable
=> new(value, hasOwnership: false);
}

/// <summary>A wrapper around an <see cref="IDisposable"/> that either owns or borrows the value.
/// Use <see cref="Disposable.Owned{TDisposable}"/> or <see cref="Disposable.Borrowed{TDisposable}"/> to create an instance of this wrapper.</summary>
/// Use <see cref="Disposable.Owned{TDisposable}(TDisposable)"/> or <see cref="Disposable.Borrowed{TDisposable}"/> to create an instance of this wrapper.</summary>
#if DISPOWNERSHIP_VISIBILITY_PUBLIC
public
#else
internal
#endif
struct Disposable<TDisposable> : IDisposable
sealed class Disposable<TDisposable> : IDisposable
where TDisposable : IDisposable
{
private readonly TDisposable _inner;
Expand Down
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog
## 0.2.0
* Add convenience overload for `Disposable.Owned` that helps with analyzers such as `IDisposableAnalyzers`.
* Use class instead of struct for `Disposable<T>` and `AsyncDisposable<T>`.

## 0.1.0
Initial release

0 comments on commit c03d845

Please sign in to comment.