-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathAttributeSyntaxReceiver.cs
More file actions
26 lines (23 loc) · 902 Bytes
/
Copy pathAttributeSyntaxReceiver.cs
File metadata and controls
26 lines (23 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
using AutoFilterer.Generators.Extensions;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using System;
using System.Collections.Generic;
using System.Linq;
namespace DotNurse.CodeAnalysis;
public class AttributeSyntaxReceiver<TAttribute> : ISyntaxReceiver
where TAttribute : Attribute
{
public IList<ClassDeclarationSyntax> Classes { get; } = new List<ClassDeclarationSyntax>();
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
{
if (syntaxNode is ClassDeclarationSyntax classDeclarationSyntax &&
classDeclarationSyntax.AttributeLists.Count > 0 &&
classDeclarationSyntax.AttributeLists
.Any(al => al.Attributes
.Any(a => a.Name.ToString().EnsureEndsWith("Attribute").Equals(typeof(TAttribute).Name))))
{
Classes.Add(classDeclarationSyntax);
}
}
}