1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-14 04:15:41 +00:00
X10D/tools/SourceGenerator/OverloadSyntaxReceiver.cs

42 lines
1.2 KiB
C#

using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using X10D.MetaServices;
namespace SourceGenerator;
public class OverloadSyntaxReceiver : ISyntaxReceiver
{
private readonly List<MethodDeclarationSyntax> _candidateMethods = new();
public IReadOnlyList<MethodDeclarationSyntax> CandidateMethods
{
get => _candidateMethods.AsReadOnly();
}
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
{
if (syntaxNode is not MethodDeclarationSyntax methodDeclarationSyntax)
{
return;
}
if (methodDeclarationSyntax.AttributeLists.Count == 0)
{
return;
}
string attributeName = nameof(AutoOverloadAttribute).Replace("Attribute", string.Empty);
foreach (AttributeListSyntax attributeListSyntax in methodDeclarationSyntax.AttributeLists)
{
foreach (AttributeSyntax attributeSyntax in attributeListSyntax.Attributes)
{
if (attributeSyntax.Name.ToString() == attributeName)
{
_candidateMethods.Add(methodDeclarationSyntax);
break;
}
}
}
}
}