-
Notifications
You must be signed in to change notification settings - Fork 1
/
NexSyntaxReceiver.cs
38 lines (33 loc) · 1.47 KB
/
NexSyntaxReceiver.cs
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
27
28
29
30
31
32
33
34
35
36
37
38
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis;
using System.Collections.Generic;
using StrideSourceGenerator.Core;
using System.Linq;
namespace StrideSourceGenerator;
public class NexSyntaxReceiver : ISyntaxReceiver
{
TypeAttributeFinder _typeFinder = new();
public List<TypeDeclarationSyntax> TypeDeclarations { get; private set; } = new();
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
{
TypeDeclarationSyntax result = _typeFinder.FindAttribute(syntaxNode);
if (result != null && (HasDataContractAttribute(result) || HasStrideCoreDataContractAttribute(result)))
{
TypeDeclarations.Add(result);
}
}
private bool HasDataContractAttribute(TypeDeclarationSyntax typeDeclaration)
{
// Check if the type declaration has the [DataContract] attribute
return typeDeclaration.AttributeLists
.SelectMany(attributeList => attributeList.Attributes)
.Any(attribute => attribute.Name.ToString() == "DataContract");
}
private bool HasStrideCoreDataContractAttribute(TypeDeclarationSyntax typeDeclaration)
{
// Check if the type declaration has the [Stride.Core.DataContract] attribute
return typeDeclaration.AttributeLists
.SelectMany(attributeList => attributeList.Attributes)
.Any(attribute => attribute.Name.ToString() == "DataContract" && attribute.Name.ToString() == "Stride.Core.DataContract");
}
}