-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Proposal] IDisposable can be used with tuple #1898
Comments
Your second case seems over-exaggerated. You can do this today: using (a)
using (b)
using (c)
{
....
} I personally don't find that to be ugly or unreadable. |
@yaakov-h using (a)
using (b)
using (c)
{
....
} |
I dunno what refactoring tool you're using, but VS2017 15.8.5 is quite happy with what I posted, and actually de-indents the subsequent After applying Format Document, it doesn't re-indent them. Most formatting analyzers I've seen such as StyleCop are perfectly happy with directly nested usings sharing a common indentation level. However, if you're happy with the example I posted, then you should fix your broken tooling or file a bug report. We don't need the language to be changed when it is already satisfactory. |
Cool idea, but why not just remove the unnecessary parens and do this: using (a, b, c)
{
....
} Which is the same as: using (a)
{
using (b)
{
using (c)
{
....
}
}
} But there's no tuples at all, just syntactic sugar. This also allows for |
This looks like a duplicate of #1473. |
With #1623, the existing using statement will check for extension methods, so you'd then be able to write this:
That proposal is already flagged for the v8.0 milestone, so it's very likely to happen - and it would make this proposal obsolete. See also #1703 for more details. |
There's also #1174, proposing a new version of using where the existing scope is used instead of creating a new one. This would eliminate the nesting you assert makes code ugly and unreadable:
#1174 is also tagged for the v8.0 milestone and is therefore very likely to happen. |
Closing as duplicate of #1473 |
Assuming we have multiple object which can be disposed.
In order to dispose them, currently we have to dispose them manually separately or use plenty of nested 'using' blocks.
Both of ways mentioned above will cause some problem:
I think the best coding style is:
We make them a tuple and use a using block. And when we are out of the using block, all of them will be disposed by order automatically.
And I think the disposing order is important.
For instance, we have a FileStream x and a StreamReader y which is created from x, then y should be disposed before x, so we should write:
The text was updated successfully, but these errors were encountered: