Roslyn: Proposal: multiple using statements

Created on 18 Mar 2016  路  4Comments  路  Source: dotnet/roslyn

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)

Area-Language Design Discussion

Most helpful comment

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 https://github.com/dotnet/roslyn/issues/2044, but seems like a better option.

All 4 comments

Why would this be a desirable language change?

@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.

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 https://github.com/dotnet/roslyn/issues/2044, but seems like a better option.

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.

Was this page helpful?
0 / 5 - 0 ratings