/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Compilers/CSharp/Portable/Syntax/NamespaceDeclarationSyntaxReference.cs
45 строк
2 KB
CyrusNajmabadi
Draft implementation of file-scoped-namespaces (#48937)
22 июн 2021, 00:18
Не верифицирован
22 июн 2021, 00:18
1a69700
Код
Авторство
О чём код?
// 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 System.Diagnostics; using System.Threading; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Syntax; namespace Microsoft.CodeAnalysis.CSharp { /// <summary> /// A SyntaxReference implementation that lazily translates the result (CSharpSyntaxNode) of the /// original syntax reference to a syntax reference for its NamespaceDeclarationSyntax. /// </summary> internal sealed class NamespaceDeclarationSyntaxReference : TranslationSyntaxReference { public NamespaceDeclarationSyntaxReference(SyntaxReference reference) : base(reference) { } protected override SyntaxNode Translate(SyntaxReference reference, CancellationToken cancellationToken) { return GetSyntax(reference, cancellationToken); } internal static SyntaxNode GetSyntax(SyntaxReference reference, CancellationToken cancellationToken) { var node = (CSharpSyntaxNode)reference.GetSyntax(cancellationToken); // If the node is a name syntax, it's something like "X" or "X.Y" in : // namespace X.Y.Z // We want to return the full NamespaceDeclarationSyntax. while (node is NameSyntax) { node = node.Parent; } Debug.Assert(node is CompilationUnitSyntax || node is BaseNamespaceDeclarationSyntax); return node; } } }