/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/EditorFeatures/CSharpTest/Utilities/CSharpServiceTestExtensions.cs
51 строка
1 KB
Cyrus Najmabadi
Move to file scoped namespace in tests
22 май 2024, 08:23
22 май 2024, 08:23
32e21b6
Код
Авторство
О чём код?
// 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. #nullable disable using System.Linq; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace Microsoft.CodeAnalysis.Editor.CSharp.UnitTests; internal static class CSharpServiceTestExtensions { /// <summary> /// DFS search to find the first node of a given type. /// </summary> internal static T FindFirstNodeOfType<T>(this SyntaxNode node) where T : SyntaxNode { if (node is T) { return node as T; } foreach (var child in node.ChildNodes()) { var foundNode = child.FindFirstNodeOfType<T>(); if (foundNode != null) { return foundNode; } } return null; } internal static T DigToFirstNodeOfType<T>(this SyntaxNode node) where T : SyntaxNode { return node.ChildNodes().OfType<T>().First(); } internal static T DigToFirstNodeOfType<T>(this SyntaxTree syntaxTree) where T : SyntaxNode { return syntaxTree.GetRoot().DigToFirstNodeOfType<T>(); } internal static TypeDeclarationSyntax DigToFirstTypeDeclaration(this SyntaxTree syntaxTree) => (syntaxTree.GetRoot() as CompilationUnitSyntax).Members.OfType<TypeDeclarationSyntax>().First(); }