/// <summary> /// Check to see if we have a equals or not equals expression where an empty string is being /// compared. /// </summary> private static void AnalyzeBinaryExpression(IBinaryOperation binaryOperation, INamedTypeSymbol?linqExpressionTreeType, Action <Diagnostic> reportDiagnostic) { if (binaryOperation.OperatorKind is not BinaryOperatorKind.Equals and not BinaryOperatorKind.NotEquals) { return; } if (binaryOperation.LeftOperand.Type?.SpecialType != SpecialType.System_String || binaryOperation.RightOperand.Type?.SpecialType != SpecialType.System_String) { return; } if (!IsEmptyString(binaryOperation.LeftOperand) && !IsEmptyString(binaryOperation.RightOperand)) { return; } // Check if we are in a Expression<Func<T...>> context, in which case it is possible // that the underlying call doesn't have the helper so we want to bail-out. if (!binaryOperation.IsWithinExpressionTree(linqExpressionTreeType)) { reportDiagnostic(binaryOperation.Syntax.CreateDiagnostic(s_rule)); } }