-
Notifications
You must be signed in to change notification settings - Fork 4k
/
UsingDirectiveSyntax.cs
48 lines (40 loc) · 2.92 KB
/
UsingDirectiveSyntax.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace Microsoft.CodeAnalysis.CSharp.Syntax
{
public partial class UsingDirectiveSyntax
{
/// <summary>
/// Returns the name this <see cref="UsingDirectiveSyntax"/> points at, or <see langword="null"/> if it does not
/// point at a name. A normal <c>using X.Y.Z;</c> or <c>using static X.Y.Z;</c> will always point at a name and
/// will always return a value for this. However, a using-alias (e.g. <c>using x = ...;</c>) may or may not
/// point at a name and may return <see langword="null"/> here. An example of when that may happen is the type
/// on the right side of the <c>=</c> is not a name. For example <c>using x = (X.Y.Z, A.B.C);</c>. Here, as
/// the type is a tuple-type there is no name to return.
/// </summary>
public NameSyntax? Name => this.NamespaceOrType as NameSyntax;
public UsingDirectiveSyntax Update(SyntaxToken usingKeyword, SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name, SyntaxToken semicolonToken)
=> this.Update(this.GlobalKeyword, usingKeyword, staticKeyword, this.UnsafeKeyword, alias, namespaceOrType: name, semicolonToken);
public UsingDirectiveSyntax Update(SyntaxToken globalKeyword, SyntaxToken usingKeyword, SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name, SyntaxToken semicolonToken)
=> this.Update(globalKeyword, usingKeyword, staticKeyword, this.UnsafeKeyword, alias, namespaceOrType: name, semicolonToken);
public UsingDirectiveSyntax WithName(NameSyntax name)
=> WithNamespaceOrType(name);
}
}
namespace Microsoft.CodeAnalysis.CSharp
{
public partial class SyntaxFactory
{
/// <summary>Creates a new UsingDirectiveSyntax instance.</summary>
public static UsingDirectiveSyntax UsingDirective(SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name)
=> UsingDirective(globalKeyword: default, usingKeyword: default, staticKeyword, unsafeKeyword: default, alias, namespaceOrType: name, semicolonToken: default);
/// <summary>Creates a new UsingDirectiveSyntax instance.</summary>
public static UsingDirectiveSyntax UsingDirective(SyntaxToken globalKeyword, SyntaxToken usingKeyword, SyntaxToken staticKeyword, NameEqualsSyntax? alias, NameSyntax name, SyntaxToken semicolonToken)
=> UsingDirective(globalKeyword, usingKeyword, staticKeyword, unsafeKeyword: default, alias, namespaceOrType: name, semicolonToken);
/// <summary>Creates a new UsingDirectiveSyntax instance.</summary>
public static UsingDirectiveSyntax UsingDirective(NameSyntax name)
=> UsingDirective(namespaceOrType: name);
}
}