1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 23:58:48 +00:00
X10D/tools/SourceGenerator/OverloadSyntaxReceiver.cs

42 lines
1.2 KiB
C#
Raw Normal View History

2023-08-26 17:11:29 +00:00
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using X10D.MetaServices;
namespace SourceGenerator;
public class OverloadSyntaxReceiver : ISyntaxReceiver
{
2024-11-14 17:35:46 +00:00
private readonly List<MethodDeclarationSyntax> _candidateMethods = [];
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;
}
}
}
}
}