Пример #1
0
        private void AnalyzeArgAtInvocations(SyntaxNodeAnalysisContext syntaxNodeContext, CallInfoContext <TInvocationExpressionSyntax, TIndexerExpressionSyntax> callInfoContext, IList <IParameterSymbol> substituteCallParameters)
        {
            foreach (var argAtInvocation in callInfoContext.ArgAtInvocations)
            {
                var position = GetArgAtPosition(syntaxNodeContext, argAtInvocation);
                if (position.HasValue)
                {
                    if (position.Value > substituteCallParameters.Count - 1)
                    {
                        var diagnostic = Diagnostic.Create(
                            DiagnosticDescriptorsProvider.CallInfoArgumentOutOfRange,
                            argAtInvocation.GetLocation(),
                            position);

                        syntaxNodeContext.ReportDiagnostic(diagnostic);
                        continue;
                    }

                    var symbolInfo = syntaxNodeContext.SemanticModel.GetSymbolInfo(argAtInvocation);
                    if (symbolInfo.Symbol != null &&
                        symbolInfo.Symbol is IMethodSymbol argAtMethodSymbol &&
                        IsAssignableTo(syntaxNodeContext.Compilation, substituteCallParameters[position.Value].Type, argAtMethodSymbol.TypeArguments.First()) == false)
                    {
                        var diagnostic = Diagnostic.Create(
                            DiagnosticDescriptorsProvider.CallInfoCouldNotConvertParameterAtPosition,
                            argAtInvocation.GetLocation(),
                            position,
                            argAtMethodSymbol.TypeArguments.First());

                        syntaxNodeContext.ReportDiagnostic(diagnostic);
                    }
                }
            }
        }
Пример #2
0
        private void AnalyzeArgInvocations(SyntaxNodeAnalysisContext syntaxNodeContext, CallInfoContext <TInvocationExpressionSyntax, TIndexerExpressionSyntax> callInfoContext, IList <IParameterSymbol> substituteCallParameters)
        {
            foreach (var argInvocation in callInfoContext.ArgInvocations)
            {
                var symbolInfo = syntaxNodeContext.SemanticModel.GetSymbolInfo(argInvocation);
                if (symbolInfo.Symbol != null && symbolInfo.Symbol is IMethodSymbol argMethodSymbol)
                {
                    var typeSymbol     = argMethodSymbol.TypeArguments.First();
                    var parameterCount = substituteCallParameters.Count(param => IsAssignableTo(syntaxNodeContext.Compilation, param.Type, typeSymbol));
                    if (parameterCount == 0)
                    {
                        var diagnostic = Diagnostic.Create(
                            DiagnosticDescriptorsProvider.CallInfoCouldNotFindArgumentToThisCall,
                            argInvocation.GetLocation(),
                            typeSymbol);

                        syntaxNodeContext.ReportDiagnostic(diagnostic);
                        continue;
                    }

                    if (parameterCount > 1)
                    {
                        var diagnostic = Diagnostic.Create(
                            DiagnosticDescriptorsProvider.CallInfoMoreThanOneArgumentOfType,
                            argInvocation.GetLocation(),
                            typeSymbol);

                        syntaxNodeContext.ReportDiagnostic(diagnostic);
                    }
                }
            }
        }
Пример #3
0
        private void AnalyzeIndexerInvocations(SyntaxNodeAnalysisContext syntaxNodeContext, CallInfoContext <TInvocationExpressionSyntax, TIndexerExpressionSyntax> callInfoContext, IList <IParameterSymbol> substituteCallParameters)
        {
            foreach (var indexer in callInfoContext.IndexerAccesses)
            {
                var indexerInfo = GetIndexerInfo(syntaxNodeContext, indexer);

                var position = GetIndexerPosition(syntaxNodeContext, indexer);

                if (AnalyzeArgumentAccess(syntaxNodeContext, substituteCallParameters, indexer, position))
                {
                    continue;
                }

                if (AnalyzeCast(syntaxNodeContext, substituteCallParameters, indexer, indexerInfo, position))
                {
                    continue;
                }

                AnalyzeAssignment(syntaxNodeContext, substituteCallParameters, indexer, indexerInfo, position);
            }
        }