2023-08-26 18:08:14 +01:00
|
|
|
using Microsoft.CodeAnalysis;
|
2023-04-06 17:00:39 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|