IDEA: Allow multiple uses statements

The comma separated namespace list in a uses statement feels somewhat out of date these days. It could be a simple enhancement to allow multiple, consecutive uses statements. Each statement would optionally support a comma separate list of namespaces as currently, or could identify a single namespace.

If used, multiple uses clauses must be contiguous. That is you could not have a uses statement followed by a type declaration followed by a further uses statement.

Contiguous uses statements would have the same effect as if they were one single statement with all namespaces listed in the order in which they occur in the separate statements.

That is:

uses A;
uses B;
uses C;

Would be equivalent to:

uses A, B;
uses C;

Which would be equivalent to:

uses A, B, C;

This would then provide flexibility in organising uses clauses which could be grouped by root namespace (for example):

uses
   System,
   System.Net;
uses
   Microsoft.AspNetCore.Mvc,
   Microsoft.Extensions.Logging;
uses
   MyApp.MyNamespace;

Or, more practically, to list namespaces as discrete references that can be more easily modified without breaking valid termination of the statements (since each is individually moveable/removable, irrespective of current/starting position in the list).

uses A;
uses B;
uses C;

A small change (?) and granted not exactly a massive leap forward in terms of language technology, but might be worth considering ?

While I’m not oppose don principle, I’m not exactly sure what actual probem this solves?

You can already group (read: sort) them, now?

It would be easy for code generation.

How so? Code generation (be it CodeDom, or CG4) has no problem just emitting all namespaces in a single list?

tbh grouping was not the primary use case I had in mind. For me, it is the differentiation of the last namespace with the presence of a terminator rather than a separator that is the most significant pain. But still a small one. :slight_smile:

It is a minor problem, to be sure, but when adding namespaces to the list and needing to resort them, it is a pain to have fiddle around with terminators if the change affects the last one in the list.

uses
   A,
   B,
   D,
   C;

You cannot just move C; up in the list, you also have to replace the ; with a ‘,’ (and vice versa for the D entry). For sure this can be worked around with fugly formatting tricks:

uses
  A
  ,B
  ,D
  ,C
  ;

Although this solves the problem for the last entry in the list, it just creates a similar one for the first.

With individual uses statements:

uses A;
uses B;
uses D;
uses C;

Each statement is self-contained, allowing each to be moved relative to any other more easily.

It was perhaps a mistake to provide the grouping example first, giving the impression that it was the most important, when the intent was to show that each uses statement could still include multiple, comma separated namespaces.

Upon reflection, allowing that might make things more complicated.

It is probably simpler to make this an option: EITHER use a single comma-separated list OR multiple contiguous statements with one namespace per uses. This option could then be determined for code generation by settings/configuration (possibly even a directive to allow for per-file configuration).

btw - I think the comment from Theo is thinking of code generation/modification using plain text emitters and handlers, rather than CodeDOM generators/modifiers.

Anyway, it was just an idea. :slight_smile:

Thanks, logged as bugs://84339

No,manual code generation. - I generate code regurarly from (html) documentation, just for my own project(s); just an exe that takses the sour and writes code in text. And for that case this can be handy.

Exactly what I meant.