CSLA.NET 6.0.0
CSLA .NET is a software development framework that helps you build a reusable, maintainable object-oriented business layer for your app.
SyntaxNodeExtensions.cs
Go to the documentation of this file.
1using Microsoft.CodeAnalysis;
2using Microsoft.CodeAnalysis.CSharp;
3using Microsoft.CodeAnalysis.CSharp.Syntax;
4using System.Linq;
5
7{
8 internal static class SyntaxNodeExtensions
9 {
10 internal static bool HasUsing(this SyntaxNode @this, string qualifiedName)
11 {
12 if (@this == null)
13 {
14 return false;
15 }
16
17 if (@this.IsKind(SyntaxKind.UsingDirective))
18 {
19 var usingNode = @this as UsingDirectiveSyntax;
20
21 if (usingNode.Name.ToFullString() == qualifiedName)
22 {
23 return true;
24 }
25 }
26
27 return @this.ChildNodes().Where(_ => _.HasUsing(qualifiedName)).Any();
28 }
29
30 internal static T FindParent<T>(this SyntaxNode @this)
31 where T : SyntaxNode
32 {
33 var parentNode = @this.Parent;
34
35 while (parentNode != null)
36 {
37 if (parentNode is T parentAsTypeNode)
38 {
39 return parentAsTypeNode;
40 }
41
42 parentNode = parentNode.Parent;
43 }
44
45 return null;
46 }
47 }
48}