sdk/Sdk.Generators/FunctionMethodSyntaxReceiver.cs (21 lines of code) (raw):
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace Microsoft.Azure.Functions.Worker.Sdk.Generators
{
public partial class FunctionMetadataProviderGenerator
{
/// <summary>
/// Created on demand before each generation pass
/// </summary>
internal class FunctionMethodSyntaxReceiver : ISyntaxReceiver
{
public List<MethodDeclarationSyntax> CandidateMethods { get; } = new();
/// <summary>
/// Called for every syntax node in the compilation, we can inspect the nodes and save any information useful for generation
/// </summary>
public void OnVisitSyntaxNode(SyntaxNode syntaxNode)
{
if (syntaxNode is MethodDeclarationSyntax {AttributeLists.Count: > 0} methodSyntax)
{
// collect all methods with attributes - we will verify they are functions when we have access to symbols to get the full name
CandidateMethods.Add(methodSyntax);
}
}
}
}
}