using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp.Syntax; namespace CSV_Metrics_Logger_Generator; internal sealed class SyntaxReceiver : ISyntaxReceiver { public List DataStructures { get; } = []; #region Implementation of ISyntaxReceiver public void OnVisitSyntaxNode(SyntaxNode syntaxNode) { // // The data structures we are looking for: // - any kind of structs (record struct, readonly record struct, regular struct) // - with the attribute [CSVRecord] // // Check if the syntax node is a struct declaration: TypeDeclarationSyntax? structNode = syntaxNode switch { RecordDeclarationSyntax rds => rds, StructDeclarationSyntax sds => sds, _ => null }; // No struct? if (structNode is null) return; // Check if the struct has the attribute [CSVRecord]: if (structNode.AttributeLists.Any(asl => asl.Attributes.Any(n => n.Name.ToString() == "CSVRecord"))) this.DataStructures.Add(structNode); } #endregion }