/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/UsingDirectiveSyntaxClassifier.cs
61 строка
2 KB
Cyrus Najmabadi
Make sealed
26 мар 2025, 22:21
26 мар 2025, 22:21
d99b771
Код
Авторство
О чём код?
// 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; using System.Collections.Immutable; using System.Threading; using Microsoft.CodeAnalysis.Classification; using Microsoft.CodeAnalysis.Classification.Classifiers; using Microsoft.CodeAnalysis.Collections; using Microsoft.CodeAnalysis.CSharp.Syntax; using Microsoft.CodeAnalysis.Text; namespace Microsoft.CodeAnalysis.CSharp.Classification.Classifiers; internal sealed class UsingDirectiveSyntaxClassifier : AbstractSyntaxClassifier { public override void AddClassifications( SyntaxNode syntax, TextSpan textSpan, SemanticModel semanticModel, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken) { if (syntax is UsingDirectiveSyntax usingDirective) { ClassifyUsingDirectiveSyntax(usingDirective, semanticModel, result, cancellationToken); } } public override ImmutableArray<Type> SyntaxNodeTypes { get; } = [typeof(UsingDirectiveSyntax)]; private static void ClassifyUsingDirectiveSyntax( UsingDirectiveSyntax usingDirective, SemanticModel semanticModel, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken) { // For using aliases, we bind the target on the right of the equals and use that // binding to classify the alias. if (usingDirective.Alias != null) { var token = usingDirective.Alias.Name; var symbolInfo = semanticModel.GetSymbolInfo(usingDirective.NamespaceOrType, cancellationToken); if (symbolInfo.Symbol is ITypeSymbol typeSymbol) { var classification = GetClassificationForType(typeSymbol); if (classification != null) { result.Add(new ClassifiedSpan(token.Span, classification)); } } else if (symbolInfo.Symbol?.Kind == SymbolKind.Namespace) { result.Add(new ClassifiedSpan(token.Span, ClassificationTypeNames.NamespaceName)); } } } }