Beispiel #1
0
 private void SetScanResult([CanBeNull] NullCheckScanResult?scanResult)
 {
     if (scanResult != null)
     {
         ScanResult = scanResult;
     }
 }
        private void AnalyzeBinaryOperator(OperationAnalysisContext context, [NotNull] NullCheckScanner scanner)
        {
            var binaryOperator = (IBinaryOperation)context.Operation;

            NullCheckScanResult?scanResult = scanner.ScanBinaryOperator(binaryOperator);

            ReportForScanResult(scanResult, context.ReportDiagnostic);
        }
        private void AnalyzeIsPattern(OperationAnalysisContext context, [NotNull] NullCheckScanner scanner)
        {
            var isPattern = (IIsPatternOperation)context.Operation;

            NullCheckScanResult?scanResult = scanner.ScanIsPattern(isPattern);

            ReportForScanResult(scanResult, context.ReportDiagnostic);
        }
        private void AnalyzePropertyReference(OperationAnalysisContext context, [NotNull] NullCheckScanner scanner)
        {
            var propertyReference = (IPropertyReferenceOperation)context.Operation;

            NullCheckScanResult?scanResult = scanner.ScanPropertyReference(propertyReference);

            ReportForScanResult(scanResult, context.ReportDiagnostic);
        }
Beispiel #5
0
            public override void VisitBinaryOperator([NotNull] IBinaryOperation operation)
            {
                NullCheckScanResult?scanResult = scanner.ScanBinaryOperator(operation);

                SetScanResult(scanResult);

                base.VisitBinaryOperator(operation);
            }
Beispiel #6
0
            public override void VisitIsPattern([NotNull] IIsPatternOperation operation)
            {
                NullCheckScanResult?scanResult = scanner.ScanIsPattern(operation);

                SetScanResult(scanResult);

                base.VisitIsPattern(operation);
            }
Beispiel #7
0
            public override void VisitPropertyReference([NotNull] IPropertyReferenceOperation operation)
            {
                NullCheckScanResult?scanResult = scanner.ScanPropertyReference(operation);

                SetScanResult(scanResult);

                base.VisitPropertyReference(operation);
            }
        private void ReportForScanResult([CanBeNull] NullCheckScanResult?scanResult,
                                         [NotNull] Action <Diagnostic> reportDiagnostic)
        {
            if (scanResult != null)
            {
                IOperation operation = scanResult.Value.Target;

                reportDiagnostic(Diagnostic.Create(Rule, operation.Syntax.GetLocation(), operation.Syntax.ToString(),
                                                   scanResult.Value.Operand == NullCheckOperand.IsNull ? "null" : "not-null", scanResult.Value.Method));
            }
        }
Beispiel #9
0
        private static void AnalyzePropertyReference(OperationAnalysisContext context, [NotNull] NullCheckScanner scanner)
        {
            var propertyReference = (IPropertyReferenceOperation)context.Operation;

            NullCheckScanResult?scanResult = scanner.ScanPropertyReference(propertyReference);

            if (scanResult != null && scanResult.Value.Method == NullCheckMethod.NullableHasValueMethod)
            {
                if (propertyReference.Parent is IBinaryOperation binaryOperator &&
                    DoReportForNullableComparison(binaryOperator, scanner))
                {
                    return;
                }

                context.ReportDiagnostic(Diagnostic.Create(NullableHasValueRule, propertyReference.Syntax.GetLocation()));
            }
        }