2 implementations of ConstantValue
Microsoft.CodeAnalysis (1)
Operations\Operation.cs (1)
94public Optional<object?> ConstantValue
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (1)
Semantics\CollectionExpressionTests.cs (1)
27090Optional<object> IOperation.ConstantValue => throw null;
302 references to ConstantValue
ILLink.RoslynAnalyzer (6)
DataFlow\FeatureChecksVisitor.cs (3)
74 if (GetConstantBool (operation.ConstantValue) is false) 85 return GetConstantBool (literal.ConstantValue); 142 return GetConstantBool (constantPattern.Value.ConstantValue);
TrimAnalysis\TrimAnalysisVisitor.cs (3)
185 if (!operation.ConstantValue.HasValue && // Optimization - if there is already a constant value available, rely on the Visit(IOperation) instead 427 if (operation.ConstantValue.HasValue) { 428 object? constantValue = operation.ConstantValue.Value;
Metrics (10)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
Metrics.Legacy (10)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
Microsoft.Analyzers.Extra (8)
CallAnalysis\Fixers\LegacyLoggingFixer.FixDetails.cs (5)
48if (children[0].ConstantValue.HasValue) 50Message = children[0].ConstantValue.Value as string ?? string.Empty; 66_ = sb.Append(stringOp.ChildOperations.First().ConstantValue.Value as string); 110value = lit.ConstantValue.Value; 114value = fieldRef.ConstantValue.Value;
CallAnalysis\StartsEndsWith.cs (3)
46var s = op.Arguments[0].Value.ConstantValue.Value as string; 50if (op.Arguments.Length > 1 && op.Arguments[1].Value.ConstantValue.HasValue) 52var comp = (StringComparison)op.Arguments[1].Value.ConstantValue.Value!;
Microsoft.AspNetCore.Analyzers (2)
OptionsAnalyzer.cs (2)
28operation.Value.ConstantValue.HasValue && 33options.Add(new OptionsItem(property.Property, operation.Value.ConstantValue.Value));
Microsoft.AspNetCore.App.Analyzers (3)
Http\HeaderDictionaryIndexerAnalyzer.cs (1)
36literalOperation.ConstantValue.Value is string indexerValue)
RouteHandlers\DetectAmbiguousRoutes.cs (2)
258if (!Equals(literal.ConstantValue, otherLiteral.ConstantValue))
Microsoft.AspNetCore.Mvc.Api.Analyzers (2)
ActualApiResponseMetadataFactory.cs (1)
234if (operation.ConstantValue is { HasValue: true } constant)
ApiActionsDoNotRequireExplicitModelValidationCheckAnalyzer.cs (1)
169var constantValue = ((ILiteralOperation)operation).ConstantValue;
Microsoft.CodeAnalysis.Analyzers (37)
FixAnalyzers\FixerWithFixAllAnalyzer.cs (2)
267return argument.Value.ConstantValue.HasValue && argument.Value.ConstantValue.Value == null;
MetaAnalyzers\DiagnosticDescriptorCreationAnalyzer.cs (17)
570firstParamArgument.Value.ConstantValue.HasValue && 571firstParamArgument.Value.ConstantValue.Value is string nameOfResource && 598invocation.Arguments[0].Value.ConstantValue.HasValue && 599invocation.Arguments[0].Value.ConstantValue.Value is string nameOfResource) 941if (operation.ConstantValue.HasValue && 942operation.ConstantValue.Value is string value && 1037if (argument.Value.ConstantValue.HasValue) 1039helpLink = argument.Value.ConstantValue.Value as string; 1073if (arrayCreation.DimensionSizes[0].ConstantValue.HasValue && 1074arrayCreation.DimensionSizes[0].ConstantValue.Value is int size && 1083arrayInitializer.ElementValues.All(element => element.ConstantValue.HasValue && element.ConstantValue.Value is string)) 1085customTags = arrayInitializer.ElementValues.Select(element => (string)element.ConstantValue.Value!).ToImmutableArray(); 1118if (argument.Value.ConstantValue.HasValue && 1119argument.Value.ConstantValue.Value is bool value) 1203if (argument.Value.ConstantValue.HasValue && 1206argument.Value.ConstantValue.Value is string value)
MetaAnalyzers\DiagnosticDescriptorCreationAnalyzer_IdRangeAndCategoryValidation.cs (4)
151if (argument.Value.ConstantValue.HasValue) 155argument.Value.ConstantValue.Value is string value) 163category = fieldReference.ConstantValue.HasValue && fieldReference.ConstantValue.Value is string value ? value : fieldReference.Field.Name;
MetaAnalyzers\Fixers\DefineDiagnosticDescriptorArgumentsCorrectlyFix.cs (4)
122literal.ConstantValue.HasValue && 123literal.ConstantValue.Value is string) 160RoslynDebug.Assert(literal.ConstantValue.HasValue && literal.ConstantValue.Value is string);
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
Microsoft.CodeAnalysis.AnalyzerUtilities (26)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\PointsToAnalysis\PointsToAnalysis.PointsToDataFlowOperationVisitor.cs (2)
756if (operation.ConstantValue.HasValue) 759operation.ConstantValue.Value == null)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Analysis\ValueContentAnalysis\ValueContentAnalysis.ValueContentDataFlowOperationVisitor.cs (3)
196if (operation.ConstantValue.HasValue) 198return operation.ConstantValue.Value != null ? 199ValueContentAbstractValue.Create(operation.ConstantValue.Value, valueTypeSymbol) :
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\AnalysisEntityFactory.cs (2)
110if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is int index)
src\RoslynAnalyzers\Utilities\FlowAnalysis\FlowAnalysis\Framework\DataFlow\DataFlowOperationVisitor.cs (9)
746branch.BranchValue.ConstantValue.HasValue) 748var alwaysTrue = (bool)branch.BranchValue.ConstantValue.Value!; 1281if (patternOperation is IConstantPatternOperation { Value.ConstantValue: { HasValue: true, Value: null } }) 1788if (operation is IConstantPatternOperation constant && constant.Value.ConstantValue.HasValue && constant.Value.ConstantValue.Value is null) 1806if (operation is INegatedPatternOperation negated && negated.Pattern is IConstantPatternOperation constant && constant.Value.ConstantValue.HasValue && constant.Value.ConstantValue.Value is null) 1855var leftConstantValueOpt = operation.LeftOperand.ConstantValue; 1857var rightConstantValueOpt = operation.RightOperand.ConstantValue;
Microsoft.CodeAnalysis.BannedApiAnalyzers (10)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
Microsoft.CodeAnalysis.CodeStyle (31)
src\Analyzers\Core\Analyzers\PopulateSwitch\AbstractPopulateSwitchExpressionDiagnosticAnalyzer.cs (1)
43ConstantValueEquals(constantPattern.Value.ConstantValue, value))
src\Analyzers\Core\Analyzers\PopulateSwitch\AbstractPopulateSwitchStatementDiagnosticAnalyzer.cs (2)
48ConstantValueEquals(singleValueCase.Value.ConstantValue, value)) 53ConstantValueEquals(constantPattern.Value.ConstantValue, value))
src\Analyzers\Core\Analyzers\PopulateSwitch\PopulateSwitchExpressionHelpers.cs (3)
44if (arm.Pattern is IConstantPatternOperation { Value.ConstantValue: { HasValue: true, Value: null } }) 78if (operation is IConstantPatternOperation { Value.ConstantValue: { HasValue: true, Value: not null and var value } }) 120if (pattern is IConstantPatternOperation { Value: IConversionOperation { ConstantValue: { HasValue: true, Value: null } } })
src\Analyzers\Core\Analyzers\PopulateSwitch\PopulateSwitchStatementHelpers.cs (6)
44if (patternCaseClause.Guard.ConstantValue.Value is true) 89if (value.ConstantValue is { HasValue: true, Value: null }) 119if (value is null || !value.ConstantValue.HasValue) 129if (value.ConstantValue.Value is null) 132var caseValue = IntegerUtilities.ToInt64(value.ConstantValue.Value); 197case ISingleValueCaseClauseOperation { Value: IConversionOperation { ConstantValue: { HasValue: true, Value: null } } }:
src\Analyzers\Core\Analyzers\RemoveRedundantEquality\AbstractRemoveRedundantEqualityDiagnosticAnalyzer.cs (2)
39if (operation.Pattern is not IConstantPatternOperation { Value.ConstantValue.Value: true or false } constantPattern) 127ConstantValue: { HasValue: true, Value: bool constValue }
src\Analyzers\Core\Analyzers\RemoveUnnecessarySuppressions\SuppressMessageAttributeState.cs (2)
138value.ConstantValue.HasValue && 139value.ConstantValue.Value is string stringValue)
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (1)
371if (!initializer.Value.ConstantValue.HasValue)
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (2)
192value.ConstantValue.HasValue) 659if (assignmentValue.ConstantValue.HasValue)
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (3)
102if (invocation.Arguments[0].Value is ILiteralOperation { ConstantValue: { HasValue: true, Value: string value } } literal && 225? alignmentOp is { ConstantValue.HasValue: true } 262=> argument.Value.ConstantValue is { HasValue: true, Value: ' ' };
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForAssignment\UseConditionalExpressionForAssignmentHelpers.cs (2)
166if (binaryOperation.LeftOperand.ConstantValue is { HasValue: true, Value: null }) 170else if (binaryOperation.RightOperand.ConstantValue is { HasValue: true, Value: null })
src\Analyzers\Core\Analyzers\UseConditionalExpression\UseConditionalExpressionHelpers.cs (1)
118=> trueValue is ILiteralOperation { ConstantValue: { HasValue: true, Value: bool value } } && value == val;
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (2)
264return operation.ConstantValue.HasValue && 265operation.ConstantValue.Value == null;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (1)
381=> operand is ILiteralOperation { ConstantValue: { HasValue: true, Value: null } };
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\CustomDataFlowAnalysis.cs (2)
148if (current.BranchValue.ConstantValue.HasValue && current.BranchValue.ConstantValue.Value is bool constant)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (1)
484if (currentOperation.ConstantValue.Value is null)
Microsoft.CodeAnalysis.CodeStyle.Fixes (5)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (5)
438var numericValue = numericLiteralExpression.ConstantValue; 477if (operation?.Kind == OperationKind.Literal && operation.ConstantValue.HasValue && operation.ConstantValue.Value is true) 481else if (operation?.Kind == OperationKind.Literal && operation.ConstantValue.HasValue && operation.ConstantValue.Value is false)
Microsoft.CodeAnalysis.CSharp.CodeStyle (6)
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\CSharpUseRangeOperatorDiagnosticAnalyzer.cs (2)
334=> operation.ConstantValue.HasValue && 335operation.ConstantValue.Value is int i &&
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (1)
163: operation.ConstantValue.HasValue;
src\Analyzers\CSharp\Analyzers\UseUtf8StringLiteral\UseUtf8StringLiteralDiagnosticAnalyzer.cs (1)
207if (element.ConstantValue.Value is not byte b)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (2)
1014=> operation.ConstantValue.HasValue && operation.ConstantValue.Value is null;
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (5)
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (4)
705ConstantValue.HasValue: true, 706ConstantValue.Value: false, 889ConstantValue.HasValue: true, 890ConstantValue.Value: true,
src\Analyzers\CSharp\CodeFixes\UseIndexOrRangeOperator\CSharpUseRangeOperatorCodeFixProvider.cs (1)
265=> (int)operation.ConstantValue.Value!; // Safe as we already confirmed this was an int when making the result.
Microsoft.CodeAnalysis.CSharp.Features (9)
src\Analyzers\CSharp\Analyzers\UseIndexOrRangeOperator\CSharpUseRangeOperatorDiagnosticAnalyzer.cs (2)
334=> operation.ConstantValue.HasValue && 335operation.ConstantValue.Value is int i &&
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (1)
163: operation.ConstantValue.HasValue;
src\Analyzers\CSharp\Analyzers\UseUtf8StringLiteral\UseUtf8StringLiteralDiagnosticAnalyzer.cs (1)
207if (element.ConstantValue.Value is not byte b)
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (4)
705ConstantValue.HasValue: true, 706ConstantValue.Value: false, 889ConstantValue.HasValue: true, 890ConstantValue.Value: true,
src\Analyzers\CSharp\CodeFixes\UseIndexOrRangeOperator\CSharpUseRangeOperatorCodeFixProvider.cs (1)
265=> (int)operation.ConstantValue.Value!; // Safe as we already confirmed this was an int when making the result.
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (1)
Semantics\ConstantTests.cs (1)
3532Assert.Equal(stringTextBuilder.ToString(), literalOperation.ConstantValue);
Microsoft.CodeAnalysis.CSharp.Workspaces (2)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (2)
1014=> operation.ConstantValue.HasValue && operation.ConstantValue.Value is null;
Microsoft.CodeAnalysis.Features (28)
ConvertIfToSwitch\AbstractConvertIfToSwitchCodeRefactoringProvider.Analyzer.cs (1)
446: operation.ConstantValue.HasValue;
src\Analyzers\Core\Analyzers\PopulateSwitch\AbstractPopulateSwitchExpressionDiagnosticAnalyzer.cs (1)
43ConstantValueEquals(constantPattern.Value.ConstantValue, value))
src\Analyzers\Core\Analyzers\PopulateSwitch\AbstractPopulateSwitchStatementDiagnosticAnalyzer.cs (2)
48ConstantValueEquals(singleValueCase.Value.ConstantValue, value)) 53ConstantValueEquals(constantPattern.Value.ConstantValue, value))
src\Analyzers\Core\Analyzers\PopulateSwitch\PopulateSwitchExpressionHelpers.cs (3)
44if (arm.Pattern is IConstantPatternOperation { Value.ConstantValue: { HasValue: true, Value: null } }) 78if (operation is IConstantPatternOperation { Value.ConstantValue: { HasValue: true, Value: not null and var value } }) 120if (pattern is IConstantPatternOperation { Value: IConversionOperation { ConstantValue: { HasValue: true, Value: null } } })
src\Analyzers\Core\Analyzers\PopulateSwitch\PopulateSwitchStatementHelpers.cs (6)
44if (patternCaseClause.Guard.ConstantValue.Value is true) 89if (value.ConstantValue is { HasValue: true, Value: null }) 119if (value is null || !value.ConstantValue.HasValue) 129if (value.ConstantValue.Value is null) 132var caseValue = IntegerUtilities.ToInt64(value.ConstantValue.Value); 197case ISingleValueCaseClauseOperation { Value: IConversionOperation { ConstantValue: { HasValue: true, Value: null } } }:
src\Analyzers\Core\Analyzers\RemoveRedundantEquality\AbstractRemoveRedundantEqualityDiagnosticAnalyzer.cs (2)
39if (operation.Pattern is not IConstantPatternOperation { Value.ConstantValue.Value: true or false } constantPattern) 127ConstantValue: { HasValue: true, Value: bool constValue }
src\Analyzers\Core\Analyzers\RemoveUnnecessarySuppressions\SuppressMessageAttributeState.cs (2)
138value.ConstantValue.HasValue && 139value.ConstantValue.Value is string stringValue)
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (1)
371if (!initializer.Value.ConstantValue.HasValue)
src\Analyzers\Core\Analyzers\RemoveUnusedParametersAndValues\AbstractRemoveUnusedParametersAndValuesDiagnosticAnalyzer.SymbolStartAnalyzer.BlockAnalyzer.cs (2)
192value.ConstantValue.HasValue) 659if (assignmentValue.ConstantValue.HasValue)
src\Analyzers\Core\Analyzers\SimplifyInterpolation\AbstractSimplifyInterpolationHelpers.cs (3)
102if (invocation.Arguments[0].Value is ILiteralOperation { ConstantValue: { HasValue: true, Value: string value } } literal && 225? alignmentOp is { ConstantValue.HasValue: true } 262=> argument.Value.ConstantValue is { HasValue: true, Value: ' ' };
src\Analyzers\Core\Analyzers\UseConditionalExpression\ForAssignment\UseConditionalExpressionForAssignmentHelpers.cs (2)
166if (binaryOperation.LeftOperand.ConstantValue is { HasValue: true, Value: null }) 170else if (binaryOperation.RightOperand.ConstantValue is { HasValue: true, Value: null })
src\Analyzers\Core\Analyzers\UseConditionalExpression\UseConditionalExpressionHelpers.cs (1)
118=> trueValue is ILiteralOperation { ConstantValue: { HasValue: true, Value: bool value } } && value == val;
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (2)
264return operation.ConstantValue.HasValue && 265operation.ConstantValue.Value == null;
Microsoft.CodeAnalysis.ResxSourceGenerator (10)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
Microsoft.CodeAnalysis.Test.Utilities (38)
Compilation\OperationTreeVerifier.cs (2)
110if (operation.ConstantValue.HasValue) 113LogConstant(operation.ConstantValue);
Compilation\TestOperationVisitor.cs (8)
48var constantValue = operation.ConstantValue; 1362Assert.False(pattern.ConstantValue.HasValue); 1550Assert.False(operation.ConstantValue.HasValue); 1560Assert.False(operation.ConstantValue.HasValue); 1723if (!operation.Value.ConstantValue.HasValue || operation.Value.ConstantValue.Value != null) 1801Assert.False(operation.ConstantValue.HasValue); 1827Assert.False(operation.ConstantValue.HasValue);
Diagnostics\EmptyArrayAnalyzer.cs (1)
78Optional<object> arrayLength = arrayCreation.DimensionSizes[0].ConstantValue;
Diagnostics\LocalCouldBeConstAnalyzer.cs (1)
92if (initializer != null && initializer.Value.ConstantValue.HasValue)
Diagnostics\OperationTestAnalyzer.cs (24)
158if (conditionRight.ConstantValue.HasValue && 164int testValue = (int)conditionRight.ConstantValue.Value; 175setupAssignment.Value.ConstantValue.HasValue && 180int initialValue = (int)setupAssignment.Value.ConstantValue.Value; 249advanceOperation.RightOperand.ConstantValue.HasValue && 253advanceIncrementOpt = advanceOperation.RightOperand.ConstantValue; 264advanceAssignment.Value.ConstantValue.HasValue && 268advanceIncrementOpt = advanceAssignment.Value.ConstantValue; 356singleValueExpression.ConstantValue.HasValue && 359int singleValue = (int)singleValueExpression.ConstantValue.Value; 376rangeMinExpression.ConstantValue.HasValue && 379rangeMaxExpression.ConstantValue.HasValue && 382int rangeMinValue = (int)rangeMinExpression.ConstantValue.Value; 383int rangeMaxValue = (int)rangeMaxExpression.ConstantValue.Value; 399relationalValueExpression.ConstantValue.HasValue && 404int relationalValue = (int)relationalValueExpression.ConstantValue.Value; 586Optional<object> argumentValue = argument.ConstantValue; 632literal.ConstantValue.HasValue && 633(int)literal.ConstantValue.Value == 17) 668if (argument.Value.ConstantValue.HasValue && argument.Value.ConstantValue.Value == null) 1108Optional<object> dimensionSize = arrayValue.DimensionSizes[0].ConstantValue; 1135Optional<object> dimensionSize = arrayValue.DimensionSizes[0].ConstantValue; 1622var rightValue = right.ConstantValue;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\CustomDataFlowAnalysis.cs (2)
148if (current.BranchValue.ConstantValue.HasValue && current.BranchValue.ConstantValue.Value is bool constant)
Microsoft.CodeAnalysis.Workspaces (9)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (1)
381=> operand is ILiteralOperation { ConstantValue: { HasValue: true, Value: null } };
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\CustomDataFlowAnalysis.cs (2)
148if (current.BranchValue.ConstantValue.HasValue && current.BranchValue.ConstantValue.Value is bool constant)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (1)
484if (currentOperation.ConstantValue.Value is null)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (5)
438var numericValue = numericLiteralExpression.ConstantValue; 477if (operation?.Kind == OperationKind.Literal && operation.ConstantValue.HasValue && operation.ConstantValue.Value is true) 481else if (operation?.Kind == OperationKind.Literal && operation.ConstantValue.HasValue && operation.ConstantValue.Value is false)
Microsoft.Interop.ComInterfaceGenerator (2)
Analyzers\ComHostingDoesNotSupportGeneratedComInterfaceAnalyzer.cs (1)
46|| ctor.Arguments[0].Value.ConstantValue.Value is not true)
src\libraries\System.Runtime.InteropServices\gen\Common\OperationExtensions.cs (1)
47return operation is { ConstantValue: { HasValue: true, Value: null } };
Microsoft.Interop.LibraryImportGenerator (2)
Analyzers\CustomMarshallerAttributeAnalyzer.cs (1)
689if (marshalModeArgument.Value is not IFieldReferenceOperation { ConstantValue.Value: var marshalMode }
src\libraries\System.Runtime.InteropServices\gen\Common\OperationExtensions.cs (1)
47return operation is { ConstantValue: { HasValue: true, Value: null } };
Microsoft.Interop.LibraryImportGenerator.Downlevel (1)
src\libraries\System.Runtime.InteropServices\gen\Common\OperationExtensions.cs (1)
47return operation is { ConstantValue: { HasValue: true, Value: null } };
Roslyn.Compilers.VisualBasic.IOperation.UnitTests (1)
IOperation\IOperationTests.vb (1)
75Assert.Equal(CInt(literal1.ConstantValue.Value), 10)
Roslyn.Diagnostics.Analyzers (10)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
Roslyn.Diagnostics.CSharp.Analyzers (1)
CSharpDoNotUseDebugAssertForInterpolatedStrings.cs (1)
68invocation.Arguments is [_, IArgumentOperation { Value: IInterpolatedStringOperation { ConstantValue.HasValue: false } }])
System.Text.RegularExpressions.Generator (10)
UpgradeToGeneratedRegexAnalyzer.cs (4)
183if (!argument.Value.ConstantValue.HasValue) 190_ = RegexParser.ParseOptionsInPattern((string)argument.Value.ConstantValue.Value!, RegexOptions.None); 206if (!argument.Value.ConstantValue.HasValue) 211RegexOptions value = (RegexOptions)(int)argument.Value.ConstantValue.Value!;
UpgradeToGeneratedRegexCodeFixer.cs (6)
263return patternArgument.Value.ConstantValue.Value as string; 270return optionsArgument is null || !optionsArgument.Value.ConstantValue.HasValue ? 272(RegexOptions)(int)optionsArgument.Value.ConstantValue.Value!; 287string optionsLiteral = Literal(((RegexOptions)(int)argument.Value.ConstantValue.Value!).ToString()); 299else if (argument.Value.ConstantValue.Value is string str && str.Contains('\\')) 305return generator.LiteralExpression(argument.Value.ConstantValue.Value);
Test.Utilities (7)
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))
Text.Analyzers (10)
src\RoslynAnalyzers\Utilities\Compiler\CodeMetrics\ComputationalComplexityMetrics.cs (3)
128if (operation.ConstantValue.HasValue) 132distinctReferencedConstantsBuilder.Add(operation.ConstantValue.Value ?? s_nullConstantPlaceholder); 331return !operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null && o.Kind is not (OperationKind.Branch or OperationKindEx.Attribute)));
src\RoslynAnalyzers\Utilities\Compiler\Extensions\IOperationExtensions.cs (7)
65return operation.ConstantValue.HasValue && operation.ConstantValue.Value == null; 70if (operation.ConstantValue.HasValue && operation.ConstantValue.Value is bool value) 87var constantValue = operation.ConstantValue; 140if (operation.DescendantsAndSelf().All(o => o.IsImplicit || (!o.ConstantValue.HasValue && o.Type == null))) 818(current.ConstantValue.HasValue || current.Type != null))