Skip to content

API proposal for "Using Alias to any Type" #66913

@CyrusNajmabadi

Description

@CyrusNajmabadi

Championed proposal: dotnet/csharplang#4284
Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/using-alias-types.md
Test Plan: #56323

Proposed API

using_directive
-  : 'global'? 'using' ('static' | name_equals)? name ';'
+  : 'global'? 'using' ('static' | ('unsafe'? name_equals))? type ';'
  ;
public sealed class UsingDirectiveSyntax
{
+    public SyntaxToken UnsafeToken { get; }
+    public TypeSyntax Type { get; }

-     public NameSyntax Name { get; }

+    /// <summary>Returns <see cref="Type"/> if it is a <see cref="NameSyntax"/>, null otherwise.</summary>
+    public NameSyntax? Name { get; }

+     // All the Update/With methods
}

public sealed class SyntaxFactory
{
+    public static UsingDirectiveSyntax UsingDirective(NameEqualsSyntax? alias, TypeSyntax type);
+    public static UsingDirectiveSyntax  UsingDirective(
+        SyntaxToken globalKeyword, SyntaxToken usingKeyword, SyntaxToken staticKeyword, SyntaxToken unsafeKeyword,
+        NameEqualsSyntax? alias, TypeSyntax type, SyntaxToken semicolonToken);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-CompilersConcept-APIThis issue involves adding, removing, clarification, or modification of an API.Feature Requestapi-approvedAPI was approved in API review, it can be implementeduntriagedIssues and PRs which have not yet been triaged by a lead

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions