/// <inheritdoc/>
            protected override bool Analyze(
                DefaultParamCompilationData compilation,
                SyntaxNodeAnalysisContext context,
                [NotNullWhen(true)] out DefaultParamDelegateData?data
                )
            {
                if (context.Node is not TypeParameterListSyntax || context.Node.Parent is not DelegateDeclarationSyntax declaration)
                {
                    data = null;
                    return(false);
                }

                IDiagnosticReceiver diagnosticReceiver = DiagnosticReceiverFactory.SyntaxNode(context);

                return(WithDiagnostics.ValidateAndCreate(diagnosticReceiver, compilation, declaration, out data, context.CancellationToken));
            }
            /// <inheritdoc/>
            protected override bool Analyze(
                DefaultParamCompilationData compilation,
                SyntaxNodeAnalysisContext context,
                [NotNullWhen(true)] out IDefaultParamTarget?data
                )
            {
                data = null;

                if (context.Node is not TypeParameterListSyntax || context.Node.Parent is not LocalFunctionStatementSyntax declaration)
                {
                    return(false);
                }

                IDiagnosticReceiver diagnosticReceiver = DiagnosticReceiverFactory.SyntaxNode(context);

                ReportDiagnosticsForLocalFunction(diagnosticReceiver, compilation, declaration, context.CancellationToken);
                return(false);
            }
Exemplo n.º 3
0
        private static void Analyze(SyntaxNodeAnalysisContext context, DefaultParamCompilationData compilation)
        {
            if (context.Node is not AttributeSyntax syntax || syntax.Parent?.Parent is not CSharpSyntaxNode parent)
            {
                return;
            }

            INamedTypeSymbol?configurationAttribute = context.SemanticModel.GetSymbolInfo(syntax).Symbol?.ContainingType;

            if (configurationAttribute is null || !SymbolEqualityComparer.Default.Equals(configurationAttribute, compilation.DefaultParamConfigurationAttribute))
            {
                return;
            }

            if (context.SemanticModel.GetDeclaredSymbol(parent) is not ISymbol symbol)
            {
                return;
            }

            ContextualDiagnosticReceiver <SyntaxNodeAnalysisContext> diagnosticReceiver = DiagnosticReceiverFactory.SyntaxNode(context);

            if (symbol is INamedTypeSymbol t)
            {
                AnalyzeType(diagnosticReceiver, t, compilation, syntax, context.CancellationToken);
            }
            else if (symbol is IMethodSymbol m)
            {
                AnalyzeMethod(diagnosticReceiver, m, compilation, syntax, context.CancellationToken);
            }
            else
            {
                ReportConfig(diagnosticReceiver, symbol, syntax);

                (AttributeArgumentSyntax syntax, string name)[] arguments = GetArguments(syntax);