/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/RoslynAnalyzers/Utilities/Workspaces/SyntaxNodeExtensions.cs
44 строки
2 KB
Joey Robichaud
Fix file headers
15 мар 2025, 02:53
15 мар 2025, 02:53
e56be3a
Код
Авторство
О чём код?
// 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.Reflection; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Simplification; namespace Analyzer.Utilities { internal static class SyntaxNodeExtensions { private static Optional<SyntaxAnnotation?> s_addImportsAnnotation; private static SyntaxAnnotation? AddImportsAnnotation { get { if (!s_addImportsAnnotation.HasValue) { var property = typeof(Simplifier).GetTypeInfo().GetDeclaredProperty("AddImportsAnnotation"); s_addImportsAnnotation = property?.GetValue(null) as SyntaxAnnotation; } return s_addImportsAnnotation.Value; } } /// <summary> /// Annotates a syntax node representing a type so that any missing imports get automatically added. Does not work in any other kinds of nodes. /// </summary> /// <param name="syntaxNode">The type node to annotate.</param> /// <returns>The annotated type node.</returns> public static SyntaxNode WithAddImportsAnnotation(this SyntaxNode syntaxNode) { if (AddImportsAnnotation is null) { return syntaxNode; } return syntaxNode.WithAdditionalAnnotations(AddImportsAnnotation); } } }