Allow using block to dispose Tuple contains some object with Dispose #8747
Replies: 4 comments 1 reply
-
Just like the tuple-of-tasks GetAwaiter() extension methods, if we get #93, you'll be able to enable the syntax you're asking for here by defining the extension method Same, if we get extension interface implementations. (Can someone confirm whether the same thing would work with #164?) |
Beta Was this translation helpful? Give feedback.
-
@jnm2 I was propose this so we could have mixed of disposable object and not disposable object in tuple like the last example I post. If it not support by tuple syntax itself, we then need to have Dispose extension for each permutation |
Beta Was this translation helpful? Give feedback.
-
We can see what they say! // Maybe
using (var x = GetDisposable(), var y = GetDisposable())
{
}
// Then
using (var x, var y) = GetDeconstructable()
{
} Dunno, seems like a rare case but it does make sense. |
Beta Was this translation helpful? Give feedback.
-
Well, thinking about it again maybe #93 would work if public static void Dispose<T0,T1>(this (T0,T1) tuple)
{
(tuple.Item0 as IDisposable)?.Dispose();
(tuple.Item1 as IDisposable)?.Dispose();
}
using(var (x,y) = GetDeconstructable())
{
// Will it dispose the x and y? Or it would dispose the GetDeconstructable() ???
} But then again it lose the Really, just let |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I wish this code be possible
Just be transpiled it to
This could also allow writing using on multiple object in one line just by tuple deconstruction
Also I wish the
using
on tuple would allow on tuple withAny object contain dispose
notAll
Beta Was this translation helpful? Give feedback.
All reactions