Skip to content

Commit

Permalink
IDisposable.AddTo returns T where T:IDisposable
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Jul 23, 2024
1 parent 91711fb commit 142ef1e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/R3/Disposable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@ public static DisposableBuilder CreateBuilder()
return new DisposableBuilder();
}

public static void AddTo(this IDisposable disposable, ref DisposableBuilder builder)
public static T AddTo<T>(this T disposable, ref DisposableBuilder builder)
where T : IDisposable
{
builder.Add(disposable);
return disposable;
}

public static void AddTo(this IDisposable disposable, ref DisposableBag bag)
public static T AddTo<T>(this T disposable, ref DisposableBag bag)
where T : IDisposable
{
bag.Add(disposable);
return disposable;
}

public static void AddTo(this IDisposable disposable, ICollection<IDisposable> disposables)
public static T AddTo<T>(this T disposable, ICollection<IDisposable> disposables)
where T : IDisposable
{
disposables.Add(disposable);
return disposable;
}

// AddTo is already used in UniTask so avoid name conflict...
Expand Down

0 comments on commit 142ef1e

Please sign in to comment.