Skip to content
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: multiple using statements #9903

Closed
EgorBo opened this issue Mar 18, 2016 · 4 comments
Closed

Proposal: multiple using statements #9903

EgorBo opened this issue Mar 18, 2016 · 4 comments

Comments

@EgorBo
Copy link
Member

EgorBo commented Mar 18, 2016

The proposal is about to have an ability to declare needed namespaces via short one-line format:

How we declare usings now:

using System;
using System.Runtime;
using System.Runtime.InteropServices;

How it can be:

using System, System.Runtime, System.Runtime.InteropServices;

And to reduce self-repeating by using some special character like '*':

using System, *.Runtime, *.InteropServices;

to let the compiler search Runtime and InteropServices in one of the previously defined namespaces (if there are more than one - to include all of them or to show a compilation error).

As an alternative, a new keyword, for example "all":

using all System.Runtime.InteropServices;

it indicates that compiler should include all intermediate namespaces as well (System and System.Runtime)

@gafter
Copy link
Member

gafter commented Mar 18, 2016

Why would this be a desirable language change?

@EgorBo
Copy link
Member Author

EgorBo commented Mar 18, 2016

@gafter For short scripts/one-liners/REPL where the "using" section can be bigger than the actual code. Also sometimes 'using' section is so big so it occupies the whole screen and 80% of text is a copy-paste.

@yufeih
Copy link
Contributor

yufeih commented Mar 21, 2016

using System, *.Runtime, *.InteropServices;

How about just introducing * to the using statement:

  • using System.Runtime.*; Imports all descendant namespaces under System.Runtime
  • using System.*; Imports all descendant namespaces under System, including System.Runtime, System.Runtime.InteropServices, etc
  • using *; Imports all namespaces from all referenced assemblies.

I tend to restrict * to only appear at last, but if using *.InteropServices has good use case, this constraint can be relaxed.

Related to #2044, but seems like a better option.

@gafter
Copy link
Member

gafter commented Mar 20, 2017

We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages.

@gafter gafter closed this as completed Mar 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants