Skip to content

AV2402: Update for ordering of using static and aliases #110

@bkoelman

Description

@bkoelman

Existing rule:

Order and group namespaces according to the company (AV2402)
Microsoft namespaces are first. Then any other namespaces in alphabetic order.

New language features to consider:

  • using static
    This enables to import a class name into scope.
  • namespace aliasing (not new, but missing)

Resharper default settings move regular namespace imports to the top, but leaves using static and using aliases unaffected. Example:

using System;
using System.Threading.Tasks;
using Custom;
using SystemConsole = System.Console;
using static Custom.Z;
using CustomX = Custom.X;
using static System.Math;

namespace ConsoleAppNewLang
{
    internal class Program
    {
        public static async Task<int> Main(string[] args)
        {
            var max = Max(1, 2);
            SystemConsole.WriteLine(max);
            return await GetAsync(new CustomX());
        }

        private static Task<int> GetAsync(CustomX x)
        {
            var y = new Y();
            var s = S;
            throw new NotImplementedException();
        }
    }
}

namespace Custom
{
    public class X
    {
    }

    public class Y
    {
    }

    public static class Z
    {
        public static string S;
    }
}

This does not help much to come up with a scheme.

Proposal: (with alphabetic ordering inside each group):

  • System namespace imports
  • Other namespace imports
  • Static namespace imports (system first)
  • Namespace alias declarations (system first)

This would require the next order for the example above:

using System;
using System.Threading.Tasks;
using Custom;
using static System.Math;
using static Custom.Z;
using SystemConsole = System.Console;
using CustomX = Custom.X;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions