private static void AnalyzeMethod()

in extensions/Worker.Extensions.Http.AspNetCore.Analyzers/src/HttpResultAttributeExpectedAnalyzer.cs [32:101]


        private static void AnalyzeMethod(SyntaxNodeAnalysisContext context)
        {
            var semanticModel = context.SemanticModel;
            var methodDeclaration = (MethodDeclarationSyntax)context.Node;

            var functionAttributeSymbol = semanticModel.Compilation.GetTypeByMetadataName(FunctionAttributeFullName);
            var functionNameAttribute = methodDeclaration.AttributeLists
                .SelectMany(attrList => attrList.Attributes)
                .Where(attr => SymbolEqualityComparer.Default.Equals(semanticModel.GetTypeInfo(attr).Type, functionAttributeSymbol));

            if (!functionNameAttribute.Any())
            {
                return;
            }

            var functionName = functionNameAttribute.First().ArgumentList.Arguments[0]; // only one argument in FunctionAttribute which is the function name

            var httpTriggerAttributeSymbol = semanticModel.Compilation.GetTypeByMetadataName(HttpTriggerAttributeFullName);
            var hasHttpTriggerAttribute = methodDeclaration.ParameterList.Parameters
                .SelectMany(param => param.AttributeLists)
                .SelectMany(attrList => attrList.Attributes)
                .Select(attr => semanticModel.GetTypeInfo(attr).Type)
                .Any(attrSymbol => SymbolEqualityComparer.Default.Equals(attrSymbol, httpTriggerAttributeSymbol));

            if (!hasHttpTriggerAttribute)
            {
                return;
            }

            var returnType = methodDeclaration.ReturnType;
            var returnTypeSymbol = semanticModel.GetTypeInfo(returnType).Type;

            if (IsHttpReturnType(returnTypeSymbol, semanticModel))
            {
                return;
            }

            var outputBindingSymbol = semanticModel.Compilation.GetTypeByMetadataName(OutputBindingFullName);
            var hasOutputBindingProperty = returnTypeSymbol.GetMembers()
                .OfType<IPropertySymbol>()
                .Any(prop => prop.GetAttributes().Any(attr => attr.AttributeClass.IsOrDerivedFrom(outputBindingSymbol)));

            if (!hasOutputBindingProperty)
            {
                return;
            }

            var httpResponseDataSymbol = semanticModel.Compilation.GetTypeByMetadataName(HttpResponseDataFullName);
            var hasHttpResponseData = returnTypeSymbol.GetMembers()
                .OfType<IPropertySymbol>()
                .Any(prop => SymbolEqualityComparer.Default.Equals(prop.Type, httpResponseDataSymbol));

            var httpResultAttributeSymbol = semanticModel.Compilation.GetTypeByMetadataName(HttpResultAttributeFullName);
            var hasHttpResultAttribute = returnTypeSymbol.GetMembers()
                .SelectMany(member => member.GetAttributes())
                .Any(attr => SymbolEqualityComparer.Default.Equals(attr.AttributeClass, httpResultAttributeSymbol));

            if (!hasHttpResultAttribute && !hasHttpResponseData)
            {
                var diagnostic = Diagnostic.Create(DiagnosticDescriptors.MultipleOutputHttpTriggerWithoutHttpResultAttribute, methodDeclaration.ReturnType.GetLocation(), functionName.ToString());
                context.ReportDiagnostic(diagnostic);
            }

            if (!hasHttpResultAttribute && hasHttpResponseData)
            {
                var diagnostic = Diagnostic.Create(DiagnosticDescriptors.MultipleOutputWithHttpResponseDataWithoutHttpResultAttribute, methodDeclaration.ReturnType.GetLocation(), functionName.ToString());
                context.ReportDiagnostic(diagnostic);
            }

        }