mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-14 21:55:41 +00:00
42 lines
1.2 KiB
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|