1053 references to BinaryOperatorKind
ILLink.RoslynAnalyzer (3)
DataFlow\FeatureChecksVisitor.cs (2)
102case BinaryOperatorKind.Equals: 105case BinaryOperatorKind.NotEquals:
TrimAnalysis\TrimAnalysisVisitor.cs (1)
195operation.OperatorKind == BinaryOperatorKind.Or &&
Metrics (24)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
Metrics.Legacy (24)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
Microsoft.AspNetCore.Mvc.Api.Analyzers (2)
ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs (2)
139if (binaryOperation.OperatorKind == BinaryOperatorKind.Equals) 145else if (binaryOperation.OperatorKind == BinaryOperatorKind.NotEquals)
Microsoft.CodeAnalysis (46)
Generated\Operations.Generated.cs (20)
1107BinaryOperatorKind OperatorKind { get; } 1516BinaryOperatorKind OperatorKind { get; } 2773BinaryOperatorKind Relation { get; } 2976BinaryOperatorKind OperatorKind { get; } 3531/// Kind of binary pattern; either <see cref="BinaryOperatorKind.And" /> or <see cref="BinaryOperatorKind.Or" />. 3533BinaryOperatorKind OperatorKind { get; } 3589BinaryOperatorKind OperatorKind { get; } 5642internal BinaryOperation(BinaryOperatorKind operatorKind, IOperation leftOperand, IOperation rightOperand, bool isLifted, bool isChecked, bool isCompareText, IMethodSymbol? operatorMethod, ITypeSymbol? constrainedToType, IMethodSymbol? unaryOperatorMethod, SemanticModel? semanticModel, SyntaxNode syntax, ITypeSymbol? type, ConstantValue? constantValue, bool isImplicit) 5657public BinaryOperatorKind OperatorKind { get; } 6306internal CompoundAssignmentOperation(IConvertibleConversion inConversion, IConvertibleConversion outConversion, BinaryOperatorKind operatorKind, bool isLifted, bool isChecked, IMethodSymbol? operatorMethod, ITypeSymbol? constrainedToType, IOperation target, IOperation value, SemanticModel? semanticModel, SyntaxNode syntax, ITypeSymbol? type, bool isImplicit) 6322public BinaryOperatorKind OperatorKind { get; } 8275internal RelationalCaseClauseOperation(IOperation value, BinaryOperatorKind relation, ILabelSymbol? label, SemanticModel? semanticModel, SyntaxNode syntax, bool isImplicit) 8282public BinaryOperatorKind Relation { get; } 8592internal TupleBinaryOperation(BinaryOperatorKind operatorKind, IOperation leftOperand, IOperation rightOperand, SemanticModel? semanticModel, SyntaxNode syntax, ITypeSymbol? type, bool isImplicit) 8600public BinaryOperatorKind OperatorKind { get; } 9889internal BinaryPatternOperation(BinaryOperatorKind operatorKind, IPatternOperation leftPattern, IPatternOperation rightPattern, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel? semanticModel, SyntaxNode syntax, bool isImplicit) 9896public BinaryOperatorKind OperatorKind { get; } 9971internal RelationalPatternOperation(BinaryOperatorKind operatorKind, IOperation value, ITypeSymbol inputType, ITypeSymbol narrowedType, SemanticModel? semanticModel, SyntaxNode syntax, bool isImplicit) 9977public BinaryOperatorKind OperatorKind { get; }
Operations\ControlFlowGraphBuilder.cs (26)
2156case BinaryOperatorKind.ConditionalOr: 2157case BinaryOperatorKind.ConditionalAnd: 2273case BinaryOperatorKind.ConditionalOr: 2277case BinaryOperatorKind.ConditionalAnd: 2539new BinaryOperation(isAndAlso ? BinaryOperatorKind.And : BinaryOperatorKind.Or, 2629new BinaryOperation(isAndAlso ? BinaryOperatorKind.And : BinaryOperatorKind.Or, 4960isUp = new BinaryOperation(BinaryOperatorKind.GreaterThanOrEqual, 5080var comparisonKind = BinaryOperatorKind.None; 5085comparisonKind = BinaryOperatorKind.LessThanOrEqual; 5092comparisonKind = BinaryOperatorKind.GreaterThanOrEqual; 5096comparisonKind = BinaryOperatorKind.LessThanOrEqual; 5103if (comparisonKind == BinaryOperatorKind.None && ITypeSymbolHelpers.IsSignedIntegralType(stepEnumUnderlyingTypeOrSelf)) 5105comparisonKind = BinaryOperatorKind.LessThanOrEqual; 5112if (comparisonKind != BinaryOperatorKind.None) 5151eitherLimitOrControlVariableIsNull = new BinaryOperation(BinaryOperatorKind.Or, 5192condition = new BinaryOperation(BinaryOperatorKind.LessThanOrEqual, 5212condition = new BinaryOperation(BinaryOperatorKind.GreaterThanOrEqual, 5246var shiftedStep = new BinaryOperation(BinaryOperatorKind.RightShift, 5261return new BinaryOperation(BinaryOperatorKind.ExclusiveOr, 5333IOperation condition = new BinaryOperation(BinaryOperatorKind.Or, 5385IOperation increment = new BinaryOperation(BinaryOperatorKind.Add, 5579condition = new BinaryOperation(BinaryOperatorKind.Equals, 5629if (relationalValueClause.Relation == BinaryOperatorKind.Equals)
Microsoft.CodeAnalysis.Analyzers (77)
MetaAnalyzers\CompareSymbolsCorrectlyAnalyzer.cs (2)
128if (binary.OperatorKind is not BinaryOperatorKind.Equals and not BinaryOperatorKind.NotEquals)
MetaAnalyzers\Fixers\CompareSymbolsCorrectlyFix.cs (1)
280if (binaryOperation.OperatorKind == BinaryOperatorKind.NotEquals)
MetaAnalyzers\PreferIsKindAnalyzer.cs (2)
73if (operation.OperatorKind is not (BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals))
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (47)
18private static readonly ImmutableDictionary<BinaryOperatorKind, BinaryOperatorKind> s_negatedBinaryMap = 19new Dictionary<BinaryOperatorKind, BinaryOperatorKind> 21{ BinaryOperatorKind.Equals, BinaryOperatorKind.NotEquals }, 22{ BinaryOperatorKind.NotEquals, BinaryOperatorKind.Equals }, 23{ BinaryOperatorKind.LessThan, BinaryOperatorKind.GreaterThanOrEqual }, 24{ BinaryOperatorKind.GreaterThan, BinaryOperatorKind.LessThanOrEqual }, 25{ BinaryOperatorKind.LessThanOrEqual, BinaryOperatorKind.GreaterThan }, 26{ BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan }, 27{ BinaryOperatorKind.Or, BinaryOperatorKind.And }, 28{ BinaryOperatorKind.And, BinaryOperatorKind.Or }, 29{ BinaryOperatorKind.ConditionalOr, BinaryOperatorKind.ConditionalAnd }, 30{ BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr }, 149if (!s_negatedBinaryMap.TryGetValue(binaryOperation.OperatorKind, out var negatedKind)) 155&& binaryOperation.OperatorKind is BinaryOperatorKind.LessThan or 156BinaryOperatorKind.LessThanOrEqual or 157BinaryOperatorKind.GreaterThan or 158BinaryOperatorKind.GreaterThanOrEqual) 163if (binaryOperation.OperatorKind is BinaryOperatorKind.Or or 164BinaryOperatorKind.And or 165BinaryOperatorKind.ConditionalAnd or 166BinaryOperatorKind.ConditionalOr) 172var newBinaryExpressionSyntax = negatedKind is BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals 380BinaryOperatorKind operationKind, 385BinaryOperatorKind.LessThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 388BinaryOperatorKind.GreaterThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 391BinaryOperatorKind.LessThan => generator.LessThanExpression(leftOperand, rightOperand), 392BinaryOperatorKind.GreaterThan => generator.GreaterThanExpression(leftOperand, rightOperand), 393BinaryOperatorKind.Or => generator.BitwiseOrExpression(leftOperand, rightOperand), 394BinaryOperatorKind.And => generator.BitwiseAndExpression(leftOperand, rightOperand), 395BinaryOperatorKind.ConditionalOr => generator.LogicalOrExpression(leftOperand, rightOperand), 396BinaryOperatorKind.ConditionalAnd => generator.LogicalAndExpression(leftOperand, rightOperand), 408BinaryOperatorKind operationKind) 418BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral() 420BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral()
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\SyntaxGeneratorInternalExtensions\SyntaxGeneratorInternal.cs (1)
108public abstract SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right);
Microsoft.CodeAnalysis.AnalyzerUtilities (88)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\DisposeAnalysis\DisposeAnalysis.DisposeDataFlowOperationVisitor.cs (4)
453(operation.OperatorKind == BinaryOperatorKind.Equals || operation.OperatorKind == BinaryOperatorKind.ObjectValueEquals); 461(operation.OperatorKind == BinaryOperatorKind.NotEquals || operation.OperatorKind == BinaryOperatorKind.ObjectValueNotEquals);
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ParameterValidationAnalysis\ParameterValidationAnalysis.ParameterValidationDataFlowOperationVisitor.cs (4)
396(operation.OperatorKind == BinaryOperatorKind.NotEquals || operation.OperatorKind == BinaryOperatorKind.ObjectValueNotEquals); 404(operation.OperatorKind == BinaryOperatorKind.Equals || operation.OperatorKind == BinaryOperatorKind.ObjectValueEquals);
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ValueContentAnalysis\ValueContentAbstractValue.cs (46)
255BinaryOperatorKind binaryOperatorKind, 289private static bool TryMerge(object? value1, object? value2, BinaryOperatorKind binaryOperatorKind, ITypeSymbol? type1, ITypeSymbol? type2, ITypeSymbol? resultType, [NotNullWhen(returnValue: true)] out object? result) 408private static bool TryMerge(char value1, char value2, BinaryOperatorKind binaryOperatorKind, [NotNullWhen(returnValue: true)] out object? result) 412case BinaryOperatorKind.Add: 413case BinaryOperatorKind.Concatenate: 422private static bool TryMerge(string value1, string value2, BinaryOperatorKind binaryOperatorKind, [NotNullWhen(returnValue: true)] out object? result) 426case BinaryOperatorKind.Add: 427case BinaryOperatorKind.Concatenate: 436private static bool TryMerge(bool value1, bool value2, BinaryOperatorKind binaryOperatorKind, [NotNullWhen(returnValue: true)] out object? result) 440case BinaryOperatorKind.And: 441case BinaryOperatorKind.ConditionalAnd: 445case BinaryOperatorKind.Or: 446case BinaryOperatorKind.ConditionalOr: 450case BinaryOperatorKind.Equals: 454case BinaryOperatorKind.NotEquals: 463private static bool TryMerge(ulong value1, ulong value2, BinaryOperatorKind binaryOperatorKind, out ulong result) 467case BinaryOperatorKind.Add: 471case BinaryOperatorKind.Subtract: 475case BinaryOperatorKind.Multiply: 479case BinaryOperatorKind.Divide: 488case BinaryOperatorKind.And: 492case BinaryOperatorKind.Or: 496case BinaryOperatorKind.Remainder: 500case BinaryOperatorKind.Power: 504case BinaryOperatorKind.LeftShift: 513case BinaryOperatorKind.RightShift: 522case BinaryOperatorKind.ExclusiveOr: 526case BinaryOperatorKind.Equals: 530case BinaryOperatorKind.NotEquals: 534case BinaryOperatorKind.LessThan: 538case BinaryOperatorKind.LessThanOrEqual: 542case BinaryOperatorKind.GreaterThan: 546case BinaryOperatorKind.GreaterThanOrEqual: 555private static bool TryMerge(double value1, double value2, BinaryOperatorKind binaryOperatorKind, out double result) 559case BinaryOperatorKind.Add: 563case BinaryOperatorKind.Subtract: 567case BinaryOperatorKind.Multiply: 571case BinaryOperatorKind.Divide: 580case BinaryOperatorKind.Remainder: 584case BinaryOperatorKind.Power: 588case BinaryOperatorKind.Equals: 592case BinaryOperatorKind.NotEquals: 596case BinaryOperatorKind.LessThan: 600case BinaryOperatorKind.LessThanOrEqual: 604case BinaryOperatorKind.GreaterThan: 608case BinaryOperatorKind.GreaterThanOrEqual:
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ValueContentAnalysis\ValueContentAnalysis.ValueContentDataFlowOperationVisitor.cs (4)
245var operationKind = operation.Kind == OperationKind.Increment ? BinaryOperatorKind.Add : BinaryOperatorKind.Subtract; 294mergedValue = mergedValue.MergeBinaryOperation(newValue, BinaryOperatorKind.Add, leftType: operation.Type, rightType: operation.Type, resultType: operation.Type);
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\DataFlowOperationVisitor.cs (6)
1796if (operation is IBinaryPatternOperation { OperatorKind: BinaryOperatorKind.Or } binaryOrOperation) 1814if (operation is IBinaryPatternOperation { OperatorKind: BinaryOperatorKind.And } binaryOrOperation) 1872case BinaryOperatorKind.Equals: 1873case BinaryOperatorKind.ObjectValueEquals: 1877case BinaryOperatorKind.NotEquals: 1878case BinaryOperatorKind.ObjectValueNotEquals:
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
Microsoft.CodeAnalysis.BannedApiAnalyzers (72)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (47)
18private static readonly ImmutableDictionary<BinaryOperatorKind, BinaryOperatorKind> s_negatedBinaryMap = 19new Dictionary<BinaryOperatorKind, BinaryOperatorKind> 21{ BinaryOperatorKind.Equals, BinaryOperatorKind.NotEquals }, 22{ BinaryOperatorKind.NotEquals, BinaryOperatorKind.Equals }, 23{ BinaryOperatorKind.LessThan, BinaryOperatorKind.GreaterThanOrEqual }, 24{ BinaryOperatorKind.GreaterThan, BinaryOperatorKind.LessThanOrEqual }, 25{ BinaryOperatorKind.LessThanOrEqual, BinaryOperatorKind.GreaterThan }, 26{ BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan }, 27{ BinaryOperatorKind.Or, BinaryOperatorKind.And }, 28{ BinaryOperatorKind.And, BinaryOperatorKind.Or }, 29{ BinaryOperatorKind.ConditionalOr, BinaryOperatorKind.ConditionalAnd }, 30{ BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr }, 149if (!s_negatedBinaryMap.TryGetValue(binaryOperation.OperatorKind, out var negatedKind)) 155&& binaryOperation.OperatorKind is BinaryOperatorKind.LessThan or 156BinaryOperatorKind.LessThanOrEqual or 157BinaryOperatorKind.GreaterThan or 158BinaryOperatorKind.GreaterThanOrEqual) 163if (binaryOperation.OperatorKind is BinaryOperatorKind.Or or 164BinaryOperatorKind.And or 165BinaryOperatorKind.ConditionalAnd or 166BinaryOperatorKind.ConditionalOr) 172var newBinaryExpressionSyntax = negatedKind is BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals 380BinaryOperatorKind operationKind, 385BinaryOperatorKind.LessThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 388BinaryOperatorKind.GreaterThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 391BinaryOperatorKind.LessThan => generator.LessThanExpression(leftOperand, rightOperand), 392BinaryOperatorKind.GreaterThan => generator.GreaterThanExpression(leftOperand, rightOperand), 393BinaryOperatorKind.Or => generator.BitwiseOrExpression(leftOperand, rightOperand), 394BinaryOperatorKind.And => generator.BitwiseAndExpression(leftOperand, rightOperand), 395BinaryOperatorKind.ConditionalOr => generator.LogicalOrExpression(leftOperand, rightOperand), 396BinaryOperatorKind.ConditionalAnd => generator.LogicalAndExpression(leftOperand, rightOperand), 408BinaryOperatorKind operationKind) 418BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral() 420BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral()
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\SyntaxGeneratorInternalExtensions\SyntaxGeneratorInternal.cs (1)
108public abstract SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right);
Microsoft.CodeAnalysis.CodeStyle (15)
src\Analyzers\Core\Analyzers\Helpers\HashCodeAnalyzer\HashCodeAnalyzer.OperationDeconstructor.cs (2)
99if (binary.OperatorKind == BinaryOperatorKind.Equals) 105else if (binary.OperatorKind == BinaryOperatorKind.NotEquals)
src\Analyzers\Core\Analyzers\PopulateSwitch\PopulateSwitchExpressionHelpers.cs (3)
66if (binaryPattern?.OperatorKind == BinaryOperatorKind.Or) 98BinaryOperatorKind.Or => IsDefault(binaryPattern.LeftPattern) || IsDefault(binaryPattern.RightPattern), 100BinaryOperatorKind.And => IsDefault(binaryPattern.LeftPattern) && IsDefault(binaryPattern.RightPattern),
src\Analyzers\Core\Analyzers\RemoveRedundantEquality\AbstractRemoveRedundantEqualityDiagnosticAnalyzer.cs (3)
65if (operation.OperatorKind is not (BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals)) 68var isOperatorEquals = operation.OperatorKind == BinaryOperatorKind.Equals;
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForAssignment\UseConditionalExpressionForAssignmentHelpers.cs (2)
163if (current is IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals } binaryOperation)
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (1)
219if (binaryOperator.OperatorKind != BinaryOperatorKind.Equals)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
Microsoft.CodeAnalysis.CodeStyle.Fixes (48)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (47)
18private static readonly ImmutableDictionary<BinaryOperatorKind, BinaryOperatorKind> s_negatedBinaryMap = 19new Dictionary<BinaryOperatorKind, BinaryOperatorKind> 21{ BinaryOperatorKind.Equals, BinaryOperatorKind.NotEquals }, 22{ BinaryOperatorKind.NotEquals, BinaryOperatorKind.Equals }, 23{ BinaryOperatorKind.LessThan, BinaryOperatorKind.GreaterThanOrEqual }, 24{ BinaryOperatorKind.GreaterThan, BinaryOperatorKind.LessThanOrEqual }, 25{ BinaryOperatorKind.LessThanOrEqual, BinaryOperatorKind.GreaterThan }, 26{ BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan }, 27{ BinaryOperatorKind.Or, BinaryOperatorKind.And }, 28{ BinaryOperatorKind.And, BinaryOperatorKind.Or }, 29{ BinaryOperatorKind.ConditionalOr, BinaryOperatorKind.ConditionalAnd }, 30{ BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr }, 149if (!s_negatedBinaryMap.TryGetValue(binaryOperation.OperatorKind, out var negatedKind)) 155&& binaryOperation.OperatorKind is BinaryOperatorKind.LessThan or 156BinaryOperatorKind.LessThanOrEqual or 157BinaryOperatorKind.GreaterThan or 158BinaryOperatorKind.GreaterThanOrEqual) 163if (binaryOperation.OperatorKind is BinaryOperatorKind.Or or 164BinaryOperatorKind.And or 165BinaryOperatorKind.ConditionalAnd or 166BinaryOperatorKind.ConditionalOr) 172var newBinaryExpressionSyntax = negatedKind is BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals 380BinaryOperatorKind operationKind, 385BinaryOperatorKind.LessThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 388BinaryOperatorKind.GreaterThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 391BinaryOperatorKind.LessThan => generator.LessThanExpression(leftOperand, rightOperand), 392BinaryOperatorKind.GreaterThan => generator.GreaterThanExpression(leftOperand, rightOperand), 393BinaryOperatorKind.Or => generator.BitwiseOrExpression(leftOperand, rightOperand), 394BinaryOperatorKind.And => generator.BitwiseAndExpression(leftOperand, rightOperand), 395BinaryOperatorKind.ConditionalOr => generator.LogicalOrExpression(leftOperand, rightOperand), 396BinaryOperatorKind.ConditionalAnd => generator.LogicalAndExpression(leftOperand, rightOperand), 408BinaryOperatorKind operationKind) 418BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral() 420BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral()
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\SyntaxGeneratorInternalExtensions\SyntaxGeneratorInternal.cs (1)
108public abstract SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right);
Microsoft.CodeAnalysis.CSharp (30)
Operations\CSharpOperationFactory.cs (9)
1359BinaryOperatorKind operatorKind = Helper.DeriveBinaryOperatorKind(boundCompoundAssignmentOperator.Operator.Kind); 1485BinaryOperatorKind operatorKind = Helper.DeriveBinaryOperatorKind(boundBinaryOperator.OperatorKind); 1509BinaryOperatorKind operatorKind = Helper.DeriveBinaryOperatorKind(boundBinaryOperator.OperatorKind); 1515(operatorKind == BinaryOperatorKind.ConditionalAnd || operatorKind == BinaryOperatorKind.ConditionalOr) && 1565BinaryOperatorKind operatorKind = Helper.DeriveBinaryOperatorKind(boundTupleBinaryOperator.OperatorKind); 2527BinaryOperatorKind operatorKind = Helper.DeriveBinaryOperatorKind(boundRelationalPattern.Relation); 2673boundBinaryPattern.Disjunction ? BinaryOperatorKind.Or : BinaryOperatorKind.And,
Operations\CSharpOperationFactory_Methods.cs (21)
547internal static BinaryOperatorKind DeriveBinaryOperatorKind(CSharp.BinaryOperatorKind operatorKind) 552return BinaryOperatorKind.Add; 555return BinaryOperatorKind.Subtract; 558return BinaryOperatorKind.Multiply; 561return BinaryOperatorKind.Divide; 564return BinaryOperatorKind.Remainder; 567return BinaryOperatorKind.LeftShift; 570return BinaryOperatorKind.RightShift; 573return BinaryOperatorKind.UnsignedRightShift; 576return BinaryOperatorKind.And; 579return BinaryOperatorKind.Or; 582return BinaryOperatorKind.ExclusiveOr; 585return BinaryOperatorKind.LessThan; 588return BinaryOperatorKind.LessThanOrEqual; 591return BinaryOperatorKind.Equals; 594return BinaryOperatorKind.NotEquals; 597return BinaryOperatorKind.GreaterThanOrEqual; 600return BinaryOperatorKind.GreaterThan; 603return BinaryOperatorKind.ConditionalAnd; 606return BinaryOperatorKind.ConditionalOr; 609return BinaryOperatorKind.None;
Microsoft.CodeAnalysis.CSharp.CodeStyle (20)
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\Helpers.cs (1)
55if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.Subtract } binaryOperation)
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\AnalyzedPattern.cs (12)
100internal sealed class Relational(BinaryOperatorKind operatorKind, ExpressionSyntax value, IOperation target) : AnalyzedPattern(target) 102public readonly BinaryOperatorKind OperatorKind = operatorKind; 184private static BinaryOperatorKind Negate(BinaryOperatorKind kind) 188BinaryOperatorKind.LessThan => BinaryOperatorKind.GreaterThanOrEqual, 189BinaryOperatorKind.GreaterThan => BinaryOperatorKind.LessThanOrEqual, 190BinaryOperatorKind.LessThanOrEqual => BinaryOperatorKind.GreaterThan, 191BinaryOperatorKind.GreaterThanOrEqual => BinaryOperatorKind.LessThan,
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (5)
11using static BinaryOperatorKind; 43case IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals } op: 124private static bool IsRelationalOperator(BinaryOperatorKind operatorKind) 146public static BinaryOperatorKind Flip(BinaryOperatorKind operatorKind)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (2)
1071private static bool ConvertedHasUserDefinedEquals(BinaryOperatorKind operatorKind, IOperation operation) 1087var opName = operatorKind == BinaryOperatorKind.Equals
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (18)
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (10)
158OperatorKind: BinaryOperatorKind.Equals, 663var expectedKind = successRequirement 664? BinaryOperatorKind.NotEquals 665: BinaryOperatorKind.Equals; 738(true, IBinaryOperation { OperatorKind: BinaryOperatorKind.ConditionalAnd } andOp) 745(false, IBinaryOperation { OperatorKind: BinaryOperatorKind.ConditionalOr } orOp) 752OperatorKind: BinaryOperatorKind.Equals, 760OperatorKind: BinaryOperatorKind.NotEquals, 804OperatorKind: BinaryOperatorKind.ConditionalAnd, 816OperatorKind: BinaryOperatorKind.ConditionalOr,
src\Analyzers\CSharp\CodeFixes\UsePatternCombinators\CSharpUsePatternCombinatorsCodeFixProvider.cs (5)
36private static SyntaxKind MapToSyntaxKind(BinaryOperatorKind kind) 40BinaryOperatorKind.LessThan => SyntaxKind.LessThanToken, 41BinaryOperatorKind.GreaterThan => SyntaxKind.GreaterThanToken, 42BinaryOperatorKind.LessThanOrEqual => SyntaxKind.LessThanEqualsToken, 43BinaryOperatorKind.GreaterThanOrEqual => SyntaxKind.GreaterThanEqualsToken,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpSyntaxGeneratorInternal.cs (3)
193public override SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right) 196BinaryOperatorKind.Equals => generator.ReferenceEqualsExpression(left, right), 197BinaryOperatorKind.NotEquals => generator.ReferenceNotEqualsExpression(left, right),
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (12)
Symbols\UserDefinedCompoundAssignmentOperatorsTests.cs (12)
12230private static Operations.BinaryOperatorKind CompoundAssignmentOperatorToBinaryOperatorKind(string op) 12234case "*=": return Operations.BinaryOperatorKind.Multiply; 12235case "/=": return Operations.BinaryOperatorKind.Divide; 12236case "%=": return Operations.BinaryOperatorKind.Remainder; 12237case "+=": return Operations.BinaryOperatorKind.Add; 12238case "-=": return Operations.BinaryOperatorKind.Subtract; 12239case ">>=": return Operations.BinaryOperatorKind.RightShift; 12240case ">>>=": return Operations.BinaryOperatorKind.UnsignedRightShift; 12241case "<<=": return Operations.BinaryOperatorKind.LeftShift; 12242case "&=": return Operations.BinaryOperatorKind.And; 12243case "|=": return Operations.BinaryOperatorKind.Or; 12244case "^=": return Operations.BinaryOperatorKind.ExclusiveOr;
Microsoft.CodeAnalysis.CSharp.Features (38)
ConvertIfToSwitch\CSharpConvertIfToSwitchCodeRefactoringProvider.Rewriting.cs (5)
22private static readonly Dictionary<BinaryOperatorKind, SyntaxKind> s_operatorMap = new() 24{ BinaryOperatorKind.LessThan, SyntaxKind.LessThanToken }, 25{ BinaryOperatorKind.GreaterThan, SyntaxKind.GreaterThanToken }, 26{ BinaryOperatorKind.LessThanOrEqual, SyntaxKind.LessThanEqualsToken }, 27{ BinaryOperatorKind.GreaterThanOrEqual, SyntaxKind.GreaterThanEqualsToken },
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\Helpers.cs (1)
55if (operation is IBinaryOperation { OperatorKind: BinaryOperatorKind.Subtract } binaryOperation)
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\AnalyzedPattern.cs (12)
100internal sealed class Relational(BinaryOperatorKind operatorKind, ExpressionSyntax value, IOperation target) : AnalyzedPattern(target) 102public readonly BinaryOperatorKind OperatorKind = operatorKind; 184private static BinaryOperatorKind Negate(BinaryOperatorKind kind) 188BinaryOperatorKind.LessThan => BinaryOperatorKind.GreaterThanOrEqual, 189BinaryOperatorKind.GreaterThan => BinaryOperatorKind.LessThanOrEqual, 190BinaryOperatorKind.LessThanOrEqual => BinaryOperatorKind.GreaterThan, 191BinaryOperatorKind.GreaterThanOrEqual => BinaryOperatorKind.LessThan,
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (5)
11using static BinaryOperatorKind; 43case IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals } op: 124private static bool IsRelationalOperator(BinaryOperatorKind operatorKind) 146public static BinaryOperatorKind Flip(BinaryOperatorKind operatorKind)
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (10)
158OperatorKind: BinaryOperatorKind.Equals, 663var expectedKind = successRequirement 664? BinaryOperatorKind.NotEquals 665: BinaryOperatorKind.Equals; 738(true, IBinaryOperation { OperatorKind: BinaryOperatorKind.ConditionalAnd } andOp) 745(false, IBinaryOperation { OperatorKind: BinaryOperatorKind.ConditionalOr } orOp) 752OperatorKind: BinaryOperatorKind.Equals, 760OperatorKind: BinaryOperatorKind.NotEquals, 804OperatorKind: BinaryOperatorKind.ConditionalAnd, 816OperatorKind: BinaryOperatorKind.ConditionalOr,
src\Analyzers\CSharp\CodeFixes\UsePatternCombinators\CSharpUsePatternCombinatorsCodeFixProvider.cs (5)
36private static SyntaxKind MapToSyntaxKind(BinaryOperatorKind kind) 40BinaryOperatorKind.LessThan => SyntaxKind.LessThanToken, 41BinaryOperatorKind.GreaterThan => SyntaxKind.GreaterThanToken, 42BinaryOperatorKind.LessThanOrEqual => SyntaxKind.LessThanEqualsToken, 43BinaryOperatorKind.GreaterThanOrEqual => SyntaxKind.GreaterThanEqualsToken,
Microsoft.CodeAnalysis.CSharp.NetAnalyzers (1)
Microsoft.NetCore.Analyzers\Runtime\CSharpUseSpanBasedStringConcat.cs (1)
20return operation.OperatorKind == BinaryOperatorKind.Add &&
Microsoft.CodeAnalysis.CSharp.Workspaces (5)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (2)
1071private static bool ConvertedHasUserDefinedEquals(BinaryOperatorKind operatorKind, IOperation operation) 1087var opName = operatorKind == BinaryOperatorKind.Equals
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpSyntaxGeneratorInternal.cs (3)
193public override SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right) 196BinaryOperatorKind.Equals => generator.ReferenceEqualsExpression(left, right), 197BinaryOperatorKind.NotEquals => generator.ReferenceNotEqualsExpression(left, right),
Microsoft.CodeAnalysis.Features (26)
ConvertIfToSwitch\AbstractConvertIfToSwitchCodeRefactoringProvider.AnalyzedNodes.cs (2)
77internal sealed class Relational(BinaryOperatorKind operatorKind, TExpressionSyntax value) : AnalyzedPattern 79public readonly BinaryOperatorKind OperatorKind = operatorKind;
ConvertIfToSwitch\AbstractConvertIfToSwitchCodeRefactoringProvider.Analyzer.cs (5)
14using static BinaryOperatorKind; 285case IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals } op: 415private static BinaryOperatorKind Flip(BinaryOperatorKind operatorKind) 428private static bool IsRelationalOperator(BinaryOperatorKind operatorKind)
InitializeParameter\AbstractAddParameterCheckCodeRefactoringProvider.cs (8)
307if (condition is IBinaryOperation { OperatorKind: BinaryOperatorKind.LessThan or BinaryOperatorKind.LessThanOrEqual or BinaryOperatorKind.GreaterThan or BinaryOperatorKind.GreaterThanOrEqual } binaryOperator && 320OperatorKind: BinaryOperatorKind.LessThan or BinaryOperatorKind.LessThanOrEqual or BinaryOperatorKind.GreaterThan or BinaryOperatorKind.GreaterThanOrEqual,
src\Analyzers\Core\Analyzers\Helpers\HashCodeAnalyzer\HashCodeAnalyzer.OperationDeconstructor.cs (2)
99if (binary.OperatorKind == BinaryOperatorKind.Equals) 105else if (binary.OperatorKind == BinaryOperatorKind.NotEquals)
src\Analyzers\Core\Analyzers\PopulateSwitch\PopulateSwitchExpressionHelpers.cs (3)
66if (binaryPattern?.OperatorKind == BinaryOperatorKind.Or) 98BinaryOperatorKind.Or => IsDefault(binaryPattern.LeftPattern) || IsDefault(binaryPattern.RightPattern), 100BinaryOperatorKind.And => IsDefault(binaryPattern.LeftPattern) && IsDefault(binaryPattern.RightPattern),
src\Analyzers\Core\Analyzers\RemoveRedundantEquality\AbstractRemoveRedundantEqualityDiagnosticAnalyzer.cs (3)
65if (operation.OperatorKind is not (BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals)) 68var isOperatorEquals = operation.OperatorKind == BinaryOperatorKind.Equals;
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForAssignment\UseConditionalExpressionForAssignmentHelpers.cs (2)
163if (current is IBinaryOperation { OperatorKind: BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals } binaryOperation)
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (1)
219if (binaryOperator.OperatorKind != BinaryOperatorKind.Equals)
Microsoft.CodeAnalysis.NetAnalyzers.UnitTests (127)
Microsoft.NetCore.Analyzers\Performance\DoNotUseCountWhenAnyCanBeUsedTests.Code.cs (21)
63internal string GetTargetExpressionBinaryExpressionCode(int value, BinaryOperatorKind @operator, bool withPredicate, string methodName) 66internal string GetTargetExpressionBinaryExpressionCode(BinaryOperatorKind @operator, int value, bool withPredicate, string methodName) 78internal string GetTargetPropertyBinaryExpressionCode(int value, BinaryOperatorKind @operator, string propertyName) 81internal string GetTargetPropertyBinaryExpressionCode(BinaryOperatorKind @operator, int value, string propertyName) 96public abstract string GetOperatorCode(BinaryOperatorKind binaryOperatorKind); 210public override string GetOperatorCode(BinaryOperatorKind binaryOperatorKind) 214BinaryOperatorKind.Add => "+", 215BinaryOperatorKind.Equals => "==", 216BinaryOperatorKind.GreaterThan => ">", 217BinaryOperatorKind.GreaterThanOrEqual => ">=", 218BinaryOperatorKind.LessThan => "<", 219BinaryOperatorKind.LessThanOrEqual => "<=", 220BinaryOperatorKind.NotEquals => "!=", 357public override string GetOperatorCode(BinaryOperatorKind binaryOperatorKind) 361BinaryOperatorKind.Add => "+", 362BinaryOperatorKind.Equals => "=", 363BinaryOperatorKind.GreaterThan => ">", 364BinaryOperatorKind.GreaterThanOrEqual => ">=", 365BinaryOperatorKind.LessThan => "<", 366BinaryOperatorKind.LessThanOrEqual => "<=", 367BinaryOperatorKind.NotEquals => "<>",
Microsoft.NetCore.Analyzers\Performance\DoNotUseCountWhenAnyCanBeUsedTests.Data.cs (68)
10public static TheoryData<BinaryOperatorKind, int> LeftCount_NoDiagnostic_TheoryData { get; } = new TheoryData<BinaryOperatorKind, int> 12{ BinaryOperatorKind.Equals , 1 }, 13{ BinaryOperatorKind.NotEquals , 1 }, 14{ BinaryOperatorKind.LessThanOrEqual , 1 }, 15{ BinaryOperatorKind.GreaterThan , 1 }, 16{ BinaryOperatorKind.LessThan , 0 }, 17{ BinaryOperatorKind.GreaterThanOrEqual, 0 }, 18{ BinaryOperatorKind.Equals , 2 }, 19{ BinaryOperatorKind.NotEquals , 2 }, 20{ BinaryOperatorKind.LessThanOrEqual , 2 }, 21{ BinaryOperatorKind.GreaterThan , 2 }, 22{ BinaryOperatorKind.LessThan , 2 }, 23{ BinaryOperatorKind.GreaterThanOrEqual, 2 }, 26public static TheoryData<BinaryOperatorKind, int, bool> LeftCount_NoDiagnostic_Predicate_TheoryData { get; } = Build_LeftCount_NoDiagnostic_Predicate_TheoryData(); 28private static TheoryData<BinaryOperatorKind, int, bool> Build_LeftCount_NoDiagnostic_Predicate_TheoryData() 30var theoryData = new TheoryData<BinaryOperatorKind, int, bool>(); 35theoryData.Add((BinaryOperatorKind)fixerData[0], (int)fixerData[1], withPredicate); 42public static TheoryData<int, BinaryOperatorKind> RightCount_NoDiagnostic_TheoryData { get; } = new TheoryData<int, BinaryOperatorKind> 44{ 1, BinaryOperatorKind.Equals }, 45{ 1, BinaryOperatorKind.NotEquals }, 46{ 1, BinaryOperatorKind.LessThan }, 47{ 1, BinaryOperatorKind.GreaterThanOrEqual }, 48{ 0, BinaryOperatorKind.GreaterThan }, 49{ 0, BinaryOperatorKind.LessThanOrEqual }, 50{ 2, BinaryOperatorKind.Equals }, 51{ 2, BinaryOperatorKind.NotEquals }, 52{ 2, BinaryOperatorKind.LessThan }, 53{ 2, BinaryOperatorKind.GreaterThanOrEqual }, 54{ 2, BinaryOperatorKind.GreaterThan }, 55{ 2, BinaryOperatorKind.LessThanOrEqual }, 58public static TheoryData<int, BinaryOperatorKind, bool> RightCount_NoDiagnostic_Predicate_TheoryData { get; } = Build_RightCount_NoDiagnostic_Predicate_TheoryData(); 60private static TheoryData<int, BinaryOperatorKind, bool> Build_RightCount_NoDiagnostic_Predicate_TheoryData() 62var theoryData = new TheoryData<int, BinaryOperatorKind, bool>(); 67theoryData.Add((int)fixerData[0], (BinaryOperatorKind)fixerData[1], withPredicate); 74public static TheoryData<BinaryOperatorKind, int, bool> LeftCount_Fixer_TheoryData { get; } = new TheoryData<BinaryOperatorKind, int, bool> 76{ BinaryOperatorKind.Equals , 0 , true }, // !Any 77{ BinaryOperatorKind.NotEquals , 0 , false }, // Any 78{ BinaryOperatorKind.LessThanOrEqual , 0 , true }, // !Any 79{ BinaryOperatorKind.GreaterThan , 0 , false }, // Any 80{ BinaryOperatorKind.LessThan , 1 , true }, // !Any 81{ BinaryOperatorKind.GreaterThanOrEqual, 1 , false }, // Any 84public static TheoryData<BinaryOperatorKind, int, bool, bool> LeftCount_Fixer_Predicate_TheoryData { get; } = Build_LeftCount_Fixer_Predicate_TheoryData(); 86private static TheoryData<BinaryOperatorKind, int, bool, bool> Build_LeftCount_Fixer_Predicate_TheoryData() 88var theoryData = new TheoryData<BinaryOperatorKind, int, bool, bool>(); 93theoryData.Add((BinaryOperatorKind)fixerData[0], (int)fixerData[1], withPredicate, (bool)fixerData[2]); 100public static TheoryData<BinaryOperatorKind, int> LeftCount_Diagnostic_TheoryData { get; } = Build_LeftCount_Diagnostic_TheoryData(); 102private static TheoryData<BinaryOperatorKind, int> Build_LeftCount_Diagnostic_TheoryData() 104var theoryData = new TheoryData<BinaryOperatorKind, int>(); 107theoryData.Add((BinaryOperatorKind)fixerData[0], (int)fixerData[1]); 113public static TheoryData<int, BinaryOperatorKind, bool> RightCount_Fixer_TheoryData { get; } = new TheoryData<int, BinaryOperatorKind, bool> 115{ 0, BinaryOperatorKind.Equals , true }, // !Any 116{ 0, BinaryOperatorKind.NotEquals , false }, // Any 117{ 0, BinaryOperatorKind.LessThan , false }, // Any 118{ 0, BinaryOperatorKind.GreaterThanOrEqual , true }, // !Any 119{ 1, BinaryOperatorKind.GreaterThan , true }, // !Any 120{ 1, BinaryOperatorKind.LessThanOrEqual , false }, // Any 123public static TheoryData<int, BinaryOperatorKind, bool, bool> RightCount_Fixer_Predicate_TheoryData { get; } = Build_RightCount_Fixer_Predicate_TheoryData(); 125private static TheoryData<int, BinaryOperatorKind, bool, bool> Build_RightCount_Fixer_Predicate_TheoryData() 127var theoryData = new TheoryData<int, BinaryOperatorKind, bool, bool>(); 132theoryData.Add((int)fixerData[0], (BinaryOperatorKind)fixerData[1], withPredicate, (bool)fixerData[2]); 139public static TheoryData<int, BinaryOperatorKind> RightCount_Diagnostic_TheoryData { get; } = Build_RightCount_Diagnostic_TheoryData(); 141private static TheoryData<int, BinaryOperatorKind> Build_RightCount_Diagnostic_TheoryData() 143var theoryData = new TheoryData<int, BinaryOperatorKind>(); 146theoryData.Add((int)fixerData[0], (BinaryOperatorKind)fixerData[1]);
Microsoft.NetCore.Analyzers\Performance\DoNotUseCountWhenAnyCanBeUsedTests.Tests.cs (20)
67public Task LeftNotCountComparison_NoDiagnosticAsync(BinaryOperatorKind @operator, int value) 78public Task RightNotCountComparison_NoDiagnosticAsync(int value, BinaryOperatorKind @operator) 94SourceProvider.GetTargetExpressionBinaryExpressionCode(BinaryOperatorKind.Add, int.MaxValue, withPredicate, SourceProvider.MemberName), 106SourceProvider.GetTargetExpressionBinaryExpressionCode(int.MaxValue, BinaryOperatorKind.Add, withPredicate, SourceProvider.MemberName), 113public Task LeftCountComparison_NoDiagnosticAsync(BinaryOperatorKind @operator, int value, bool withPredicate) 124public Task RightCountComparison_NoDiagnosticAsync(int value, BinaryOperatorKind @operator, bool withPredicate) 135public Task LeftNotTargetCountComparison_NoDiagnosticAsync(BinaryOperatorKind @operator, int value, bool withPredicate) 146public Task RightNotTargetCountComparison_NoDiagnosticAsync(int value, BinaryOperatorKind @operator, bool withPredicate) 157public Task LeftTargetCountComparison_FixedAsync(BinaryOperatorKind @operator, int value, bool withPredicate, bool negate) 173public Task RightTargetCountComparison_FixedAsync(int value, BinaryOperatorKind @operator, bool withPredicate, bool negate) 1521public Task LeftNotCountComparison_NoDiagnosticAsync(BinaryOperatorKind @operator, int value) 1532public Task RightNotCountComparison_NoDiagnosticAsync(int value, BinaryOperatorKind @operator) 1546SourceProvider.GetTargetExpressionBinaryExpressionCode(BinaryOperatorKind.Add, int.MaxValue, withPredicate: true, SourceProvider.MemberName), 1556SourceProvider.GetTargetExpressionBinaryExpressionCode(int.MaxValue, BinaryOperatorKind.Add, withPredicate: true, SourceProvider.MemberName), 1563public Task LeftCountComparison_NoDiagnosticAsync(BinaryOperatorKind @operator, int value, bool _) 1574public Task RightCountComparison_NoDiagnosticAsync(int value, BinaryOperatorKind @operator, bool _) 1585public Task LeftNotTargetCountComparison_NoDiagnosticAsync(BinaryOperatorKind @operator, int value, bool _) 1596public Task RightNotTargetCountComparison_NoDiagnosticAsync(int value, BinaryOperatorKind @operator, bool _) 1607public Task LeftTargetCountComparison_FixedAsync(BinaryOperatorKind @operator, int value, bool _, bool negate) 1623public Task RightTargetCountComparison_FixedAsync(int value, BinaryOperatorKind @operator, bool _, bool negate)
Microsoft.NetCore.Analyzers\Performance\PreferIsEmptyOverCountTests.cs (2)
466public Task PropertyOnBinaryOperationAsync(bool noDiagnosis, int literal, BinaryOperatorKind @operator, bool isRightSideExpression, bool shouldNegate) 522public Task LinqMethodOnBinaryOperationAsync(int literal, BinaryOperatorKind @operator, bool isRightSideExpression, bool shouldNegate)
Microsoft.NetCore.Analyzers\Performance\UseCountProperlyTests.Data.cs (8)
65new OperatorKind((a, b) => a == b, 1, 2, BinaryOperatorKind.Equals), 66new OperatorKind((a, b) => a != b, 2, 2, BinaryOperatorKind.NotEquals), 67new OperatorKind((a, b) => a > b, 1, 1, BinaryOperatorKind.GreaterThan), 68new OperatorKind((a, b) => a >= b, 2, 2, BinaryOperatorKind.GreaterThanOrEqual), 69new OperatorKind((a, b) => a < b, 1, 1, BinaryOperatorKind.LessThan), 70new OperatorKind((a, b) => a <= b, 2, 2, BinaryOperatorKind.LessThanOrEqual), 80public BinaryOperatorKind BinaryOperatorKind { get; } 82public OperatorKind(Func<int, int, bool> operation, int basicOperatorLength, int csharpOperatorLength, BinaryOperatorKind operatorKind)
Microsoft.NetCore.Analyzers\Performance\UsePropertyInsteadOfCountMethodWhenAvailableTests.cs (8)
814public Task PropertyOnBinaryOperationAsync(int literal, BinaryOperatorKind @operator, bool isRightSideExpression) 843private static int GetOperatorLength(TestsSourceCodeProvider sourceProvider, BinaryOperatorKind @operator) 847case BinaryOperatorKind.GreaterThan: 848case BinaryOperatorKind.LessThan: 850case BinaryOperatorKind.NotEquals: 851case BinaryOperatorKind.GreaterThanOrEqual: 852case BinaryOperatorKind.LessThanOrEqual: 854case BinaryOperatorKind.Equals:
Microsoft.CodeAnalysis.PerformanceSensitiveAnalyzers (72)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (47)
18private static readonly ImmutableDictionary<BinaryOperatorKind, BinaryOperatorKind> s_negatedBinaryMap = 19new Dictionary<BinaryOperatorKind, BinaryOperatorKind> 21{ BinaryOperatorKind.Equals, BinaryOperatorKind.NotEquals }, 22{ BinaryOperatorKind.NotEquals, BinaryOperatorKind.Equals }, 23{ BinaryOperatorKind.LessThan, BinaryOperatorKind.GreaterThanOrEqual }, 24{ BinaryOperatorKind.GreaterThan, BinaryOperatorKind.LessThanOrEqual }, 25{ BinaryOperatorKind.LessThanOrEqual, BinaryOperatorKind.GreaterThan }, 26{ BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan }, 27{ BinaryOperatorKind.Or, BinaryOperatorKind.And }, 28{ BinaryOperatorKind.And, BinaryOperatorKind.Or }, 29{ BinaryOperatorKind.ConditionalOr, BinaryOperatorKind.ConditionalAnd }, 30{ BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr }, 149if (!s_negatedBinaryMap.TryGetValue(binaryOperation.OperatorKind, out var negatedKind)) 155&& binaryOperation.OperatorKind is BinaryOperatorKind.LessThan or 156BinaryOperatorKind.LessThanOrEqual or 157BinaryOperatorKind.GreaterThan or 158BinaryOperatorKind.GreaterThanOrEqual) 163if (binaryOperation.OperatorKind is BinaryOperatorKind.Or or 164BinaryOperatorKind.And or 165BinaryOperatorKind.ConditionalAnd or 166BinaryOperatorKind.ConditionalOr) 172var newBinaryExpressionSyntax = negatedKind is BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals 380BinaryOperatorKind operationKind, 385BinaryOperatorKind.LessThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 388BinaryOperatorKind.GreaterThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 391BinaryOperatorKind.LessThan => generator.LessThanExpression(leftOperand, rightOperand), 392BinaryOperatorKind.GreaterThan => generator.GreaterThanExpression(leftOperand, rightOperand), 393BinaryOperatorKind.Or => generator.BitwiseOrExpression(leftOperand, rightOperand), 394BinaryOperatorKind.And => generator.BitwiseAndExpression(leftOperand, rightOperand), 395BinaryOperatorKind.ConditionalOr => generator.LogicalOrExpression(leftOperand, rightOperand), 396BinaryOperatorKind.ConditionalAnd => generator.LogicalAndExpression(leftOperand, rightOperand), 408BinaryOperatorKind operationKind) 418BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral() 420BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral()
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\SyntaxGeneratorInternalExtensions\SyntaxGeneratorInternal.cs (1)
108public abstract SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right);
Microsoft.CodeAnalysis.PublicApiAnalyzers (24)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
Microsoft.CodeAnalysis.ResxSourceGenerator (24)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
Microsoft.CodeAnalysis.Test.Utilities (45)
Compilation\ControlFlowGraphVerifier.cs (6)
947(binOp.OperatorKind == Operations.BinaryOperatorKind.And || binOp.OperatorKind == Operations.BinaryOperatorKind.Or) && 973binOp.OperatorKind == Operations.BinaryOperatorKind.And && 980binOp.OperatorKind == Operations.BinaryOperatorKind.Or && 1876return (binary.OperatorKind != Operations.BinaryOperatorKind.ConditionalAnd && binary.OperatorKind != Operations.BinaryOperatorKind.ConditionalOr) ||
Compilation\OperationTreeVerifier.cs (6)
1172var kindStr = $"{nameof(BinaryOperatorKind)}.{operation.OperatorKind}"; 1200var kindStr = $"{nameof(BinaryOperatorKind)}.{operation.OperatorKind}"; 1675var kindStr = $"{nameof(BinaryOperatorKind)}.{operation.OperatorKind}"; 1828var kindStr = $"{nameof(BinaryOperatorKind)}.{operation.Relation}"; 1948LogString($" ({nameof(BinaryOperatorKind)}.{operation.OperatorKind})"); 1963LogString($" ({nameof(BinaryOperatorKind)}.{operation.OperatorKind})");
Compilation\TestOperationVisitor.cs (14)
231var relation = operation.Relation; 767var binaryOperationKind = operation.OperatorKind; 773if (binaryOperationKind is BinaryOperatorKind.ConditionalAnd or BinaryOperatorKind.ConditionalOr) 834var binaryOperationKind = operation.OperatorKind; 1173var binaryOperationKind = operation.OperatorKind; 1376Assert.True(operation.OperatorKind is Operations.BinaryOperatorKind.LessThan or 1377Operations.BinaryOperatorKind.LessThanOrEqual or 1378Operations.BinaryOperatorKind.GreaterThan or 1379Operations.BinaryOperatorKind.GreaterThanOrEqual or 1380Operations.BinaryOperatorKind.Equals or // Error cases 1381Operations.BinaryOperatorKind.NotEquals); 1390Assert.True(operation.OperatorKind switch { Operations.BinaryOperatorKind.Or => true, Operations.BinaryOperatorKind.And => true, _ => false });
Diagnostics\OperationTestAnalyzer.cs (19)
190BinaryOperatorKind? advanceOperationCode; 196if (advanceOperationCode.Value == BinaryOperatorKind.Subtract) 198advanceOperationCode = BinaryOperatorKind.Add; 202if (advanceOperationCode.Value == BinaryOperatorKind.Add && 204(condition.OperatorKind == BinaryOperatorKind.LessThan || 205condition.OperatorKind == BinaryOperatorKind.LessThanOrEqual || 206condition.OperatorKind == BinaryOperatorKind.NotEquals || 207condition.OperatorKind == BinaryOperatorKind.GreaterThan || 208condition.OperatorKind == BinaryOperatorKind.GreaterThanOrEqual)) 229out BinaryOperatorKind? advanceOperationCode, out Optional<object> advanceIncrementOpt) 281advanceOperationCode = BinaryOperatorKind.Add; 407case BinaryOperatorKind.Equals: 411case BinaryOperatorKind.NotEquals: 413case BinaryOperatorKind.LessThan: 417case BinaryOperatorKind.LessThanOrEqual: 421case BinaryOperatorKind.GreaterThanOrEqual: 425case BinaryOperatorKind.GreaterThan: 1516if (binary.OperatorKind == BinaryOperatorKind.Add && binary.OperatorMethod != null && binary.OperatorMethod.Name.Contains("Addition")) 1521if (binary.OperatorKind == BinaryOperatorKind.Multiply && binary.Type.SpecialType == SpecialType.System_Double)
Microsoft.CodeAnalysis.VisualBasic.NetAnalyzers (1)
Microsoft.NetCore.Analyzers\Runtime\BasicUseSpanBasedStringConcat.vb (1)
30Return operation.OperatorKind = BinaryOperatorKind.Concatenate
Microsoft.CodeAnalysis.Workspaces (52)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (47)
18private static readonly ImmutableDictionary<BinaryOperatorKind, BinaryOperatorKind> s_negatedBinaryMap = 19new Dictionary<BinaryOperatorKind, BinaryOperatorKind> 21{ BinaryOperatorKind.Equals, BinaryOperatorKind.NotEquals }, 22{ BinaryOperatorKind.NotEquals, BinaryOperatorKind.Equals }, 23{ BinaryOperatorKind.LessThan, BinaryOperatorKind.GreaterThanOrEqual }, 24{ BinaryOperatorKind.GreaterThan, BinaryOperatorKind.LessThanOrEqual }, 25{ BinaryOperatorKind.LessThanOrEqual, BinaryOperatorKind.GreaterThan }, 26{ BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan }, 27{ BinaryOperatorKind.Or, BinaryOperatorKind.And }, 28{ BinaryOperatorKind.And, BinaryOperatorKind.Or }, 29{ BinaryOperatorKind.ConditionalOr, BinaryOperatorKind.ConditionalAnd }, 30{ BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr }, 149if (!s_negatedBinaryMap.TryGetValue(binaryOperation.OperatorKind, out var negatedKind)) 155&& binaryOperation.OperatorKind is BinaryOperatorKind.LessThan or 156BinaryOperatorKind.LessThanOrEqual or 157BinaryOperatorKind.GreaterThan or 158BinaryOperatorKind.GreaterThanOrEqual) 163if (binaryOperation.OperatorKind is BinaryOperatorKind.Or or 164BinaryOperatorKind.And or 165BinaryOperatorKind.ConditionalAnd or 166BinaryOperatorKind.ConditionalOr) 172var newBinaryExpressionSyntax = negatedKind is BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals 380BinaryOperatorKind operationKind, 385BinaryOperatorKind.LessThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 388BinaryOperatorKind.GreaterThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 391BinaryOperatorKind.LessThan => generator.LessThanExpression(leftOperand, rightOperand), 392BinaryOperatorKind.GreaterThan => generator.GreaterThanExpression(leftOperand, rightOperand), 393BinaryOperatorKind.Or => generator.BitwiseOrExpression(leftOperand, rightOperand), 394BinaryOperatorKind.And => generator.BitwiseAndExpression(leftOperand, rightOperand), 395BinaryOperatorKind.ConditionalOr => generator.LogicalOrExpression(leftOperand, rightOperand), 396BinaryOperatorKind.ConditionalAnd => generator.LogicalAndExpression(leftOperand, rightOperand), 408BinaryOperatorKind operationKind) 418BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral() 420BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral()
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\SyntaxGeneratorInternalExtensions\SyntaxGeneratorInternal.cs (1)
108public abstract SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right);
Roslyn.Diagnostics.Analyzers (72)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (47)
18private static readonly ImmutableDictionary<BinaryOperatorKind, BinaryOperatorKind> s_negatedBinaryMap = 19new Dictionary<BinaryOperatorKind, BinaryOperatorKind> 21{ BinaryOperatorKind.Equals, BinaryOperatorKind.NotEquals }, 22{ BinaryOperatorKind.NotEquals, BinaryOperatorKind.Equals }, 23{ BinaryOperatorKind.LessThan, BinaryOperatorKind.GreaterThanOrEqual }, 24{ BinaryOperatorKind.GreaterThan, BinaryOperatorKind.LessThanOrEqual }, 25{ BinaryOperatorKind.LessThanOrEqual, BinaryOperatorKind.GreaterThan }, 26{ BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan }, 27{ BinaryOperatorKind.Or, BinaryOperatorKind.And }, 28{ BinaryOperatorKind.And, BinaryOperatorKind.Or }, 29{ BinaryOperatorKind.ConditionalOr, BinaryOperatorKind.ConditionalAnd }, 30{ BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr }, 149if (!s_negatedBinaryMap.TryGetValue(binaryOperation.OperatorKind, out var negatedKind)) 155&& binaryOperation.OperatorKind is BinaryOperatorKind.LessThan or 156BinaryOperatorKind.LessThanOrEqual or 157BinaryOperatorKind.GreaterThan or 158BinaryOperatorKind.GreaterThanOrEqual) 163if (binaryOperation.OperatorKind is BinaryOperatorKind.Or or 164BinaryOperatorKind.And or 165BinaryOperatorKind.ConditionalAnd or 166BinaryOperatorKind.ConditionalOr) 172var newBinaryExpressionSyntax = negatedKind is BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals 380BinaryOperatorKind operationKind, 385BinaryOperatorKind.LessThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 388BinaryOperatorKind.GreaterThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 391BinaryOperatorKind.LessThan => generator.LessThanExpression(leftOperand, rightOperand), 392BinaryOperatorKind.GreaterThan => generator.GreaterThanExpression(leftOperand, rightOperand), 393BinaryOperatorKind.Or => generator.BitwiseOrExpression(leftOperand, rightOperand), 394BinaryOperatorKind.And => generator.BitwiseAndExpression(leftOperand, rightOperand), 395BinaryOperatorKind.ConditionalOr => generator.LogicalOrExpression(leftOperand, rightOperand), 396BinaryOperatorKind.ConditionalAnd => generator.LogicalAndExpression(leftOperand, rightOperand), 408BinaryOperatorKind operationKind) 418BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral() 420BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral()
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\SyntaxGeneratorInternalExtensions\SyntaxGeneratorInternal.cs (1)
108public abstract SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right);
Roslyn.Diagnostics.CSharp.Analyzers (5)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (2)
1071private static bool ConvertedHasUserDefinedEquals(BinaryOperatorKind operatorKind, IOperation operation) 1087var opName = operatorKind == BinaryOperatorKind.Equals
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpSyntaxGeneratorInternal.cs (3)
193public override SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right) 196BinaryOperatorKind.Equals => generator.ReferenceEqualsExpression(left, right), 197BinaryOperatorKind.NotEquals => generator.ReferenceNotEqualsExpression(left, right),
Test.Utilities (10)
IOperationExtensions.cs (10)
399BinaryOperatorKind.Equals 400or BinaryOperatorKind.NotEquals 401or BinaryOperatorKind.ObjectValueEquals 402or BinaryOperatorKind.ObjectValueNotEquals 403or BinaryOperatorKind.LessThan 404or BinaryOperatorKind.LessThanOrEqual 405or BinaryOperatorKind.GreaterThan 406or BinaryOperatorKind.GreaterThanOrEqual => true, 420case BinaryOperatorKind.Add: 422case BinaryOperatorKind.Subtract:
Text.Analyzers (72)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (8)
26ImmutableHashSet<BinaryOperatorKind>.Empty, ImmutableHashSet<UnaryOperatorKind>.Empty, ImmutableHashSet<CaseKind>.Empty, ImmutableHashSet<ISymbol>.Empty, ImmutableHashSet<object>.Empty); 31private readonly ImmutableHashSet<BinaryOperatorKind> _distinctBinaryOperatorKinds; 44ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 70ImmutableHashSet<BinaryOperatorKind> distinctBinaryOperatorKinds, 96ImmutableHashSet<BinaryOperatorKind>.Builder? distinctBinaryOperatorKindsBuilder = null; 291distinctBinaryOperatorKindsBuilder != null ? distinctBinaryOperatorKindsBuilder.ToImmutable() : ImmutableHashSet<BinaryOperatorKind>.Empty, 349void countBinaryOperator(IOperation operation, BinaryOperatorKind operatorKind) 352distinctBinaryOperatorKindsBuilder ??= ImmutableHashSet.CreateBuilder<BinaryOperatorKind>();
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\MetricsHelper.cs (4)
338return binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalAnd || 339binaryOperation.OperatorKind == BinaryOperatorKind.ConditionalOr || 341(binaryOperation.OperatorKind == BinaryOperatorKind.Or || binaryOperation.OperatorKind == BinaryOperatorKind.And));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (8)
248BinaryOperatorKind.Equals 249or BinaryOperatorKind.NotEquals 250or BinaryOperatorKind.ObjectValueEquals 251or BinaryOperatorKind.ObjectValueNotEquals 252or BinaryOperatorKind.LessThan 253or BinaryOperatorKind.LessThanOrEqual 254or BinaryOperatorKind.GreaterThan 255or BinaryOperatorKind.GreaterThanOrEqual => true,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SemanticFacts\ISemanticFactsExtensions.cs (4)
86return op.OperatorKind is BinaryOperatorKind.Add or 87BinaryOperatorKind.Subtract or 88BinaryOperatorKind.Multiply or 89BinaryOperatorKind.Divide;
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (47)
18private static readonly ImmutableDictionary<BinaryOperatorKind, BinaryOperatorKind> s_negatedBinaryMap = 19new Dictionary<BinaryOperatorKind, BinaryOperatorKind> 21{ BinaryOperatorKind.Equals, BinaryOperatorKind.NotEquals }, 22{ BinaryOperatorKind.NotEquals, BinaryOperatorKind.Equals }, 23{ BinaryOperatorKind.LessThan, BinaryOperatorKind.GreaterThanOrEqual }, 24{ BinaryOperatorKind.GreaterThan, BinaryOperatorKind.LessThanOrEqual }, 25{ BinaryOperatorKind.LessThanOrEqual, BinaryOperatorKind.GreaterThan }, 26{ BinaryOperatorKind.GreaterThanOrEqual, BinaryOperatorKind.LessThan }, 27{ BinaryOperatorKind.Or, BinaryOperatorKind.And }, 28{ BinaryOperatorKind.And, BinaryOperatorKind.Or }, 29{ BinaryOperatorKind.ConditionalOr, BinaryOperatorKind.ConditionalAnd }, 30{ BinaryOperatorKind.ConditionalAnd, BinaryOperatorKind.ConditionalOr }, 149if (!s_negatedBinaryMap.TryGetValue(binaryOperation.OperatorKind, out var negatedKind)) 155&& binaryOperation.OperatorKind is BinaryOperatorKind.LessThan or 156BinaryOperatorKind.LessThanOrEqual or 157BinaryOperatorKind.GreaterThan or 158BinaryOperatorKind.GreaterThanOrEqual) 163if (binaryOperation.OperatorKind is BinaryOperatorKind.Or or 164BinaryOperatorKind.And or 165BinaryOperatorKind.ConditionalAnd or 166BinaryOperatorKind.ConditionalOr) 172var newBinaryExpressionSyntax = negatedKind is BinaryOperatorKind.Equals or BinaryOperatorKind.NotEquals 380BinaryOperatorKind operationKind, 385BinaryOperatorKind.LessThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 388BinaryOperatorKind.GreaterThanOrEqual => IsSpecialCaseBinaryExpression(binaryOperation, operationKind) 391BinaryOperatorKind.LessThan => generator.LessThanExpression(leftOperand, rightOperand), 392BinaryOperatorKind.GreaterThan => generator.GreaterThanExpression(leftOperand, rightOperand), 393BinaryOperatorKind.Or => generator.BitwiseOrExpression(leftOperand, rightOperand), 394BinaryOperatorKind.And => generator.BitwiseAndExpression(leftOperand, rightOperand), 395BinaryOperatorKind.ConditionalOr => generator.LogicalOrExpression(leftOperand, rightOperand), 396BinaryOperatorKind.ConditionalAnd => generator.LogicalAndExpression(leftOperand, rightOperand), 408BinaryOperatorKind operationKind) 418BinaryOperatorKind.LessThanOrEqual when rightOperand.IsNumericLiteral() 420BinaryOperatorKind.GreaterThanOrEqual when leftOperand.IsNumericLiteral()
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\LanguageServices\SyntaxGeneratorInternalExtensions\SyntaxGeneratorInternal.cs (1)
108public abstract SyntaxNode NegateEquality(SyntaxGenerator generator, SyntaxNode binaryExpression, SyntaxNode left, BinaryOperatorKind negatedKind, SyntaxNode right);