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;
167 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;
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.CodeStyle (29)
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)
139value.ConstantValue.HasValue && 140value.ConstantValue.Value is string stringValue)
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (1)
311if (!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)
90if (invocation.Arguments[0].Value is ILiteralOperation { ConstantValue: { HasValue: true, Value: string value } } literal && 211? alignmentOp is { ConstantValue.HasValue: true } 248=> argument.Value.ConstantValue is { HasValue: true, Value: ' ' };
src\Analyzers\Core\Analyzers\UseConditionalExpression\UseConditionalExpressionHelpers.cs (1)
105=> trueValue is ILiteralOperation { ConstantValue: { HasValue: true, Value: bool value } } && value == val;
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (2)
265return operation.ConstantValue.HasValue && 266operation.ConstantValue.Value == null;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (1)
378=> operand is ILiteralOperation { ConstantValue: { HasValue: true, Value: null } };
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\CustomDataFlowAnalysis.cs (2)
149if (current.BranchValue.ConstantValue.HasValue && current.BranchValue.ConstantValue.Value is bool constant)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (1)
485if (currentOperation.ConstantValue.Value is null)
Microsoft.CodeAnalysis.CodeStyle.Fixes (5)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (5)
440var numericValue = numericLiteralExpression.ConstantValue; 479if (operation?.Kind == OperationKind.Literal && operation.ConstantValue.HasValue && operation.ConstantValue.Value is true) 483else 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)
335=> operation.ConstantValue.HasValue && 336operation.ConstantValue.Value is int i &&
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (1)
164: 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)
976=> operation.ConstantValue.HasValue && operation.ConstantValue.Value is null;
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (5)
src\Analyzers\CSharp\CodeFixes\ConvertToRecord\ConvertToRecordHelpers.cs (4)
706ConstantValue.HasValue: true, 707ConstantValue.Value: false, 890ConstantValue.HasValue: true, 891ConstantValue.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)
335=> operation.ConstantValue.HasValue && 336operation.ConstantValue.Value is int i &&
src\Analyzers\CSharp\Analyzers\UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs (1)
164: 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)
706ConstantValue.HasValue: true, 707ConstantValue.Value: false, 890ConstantValue.HasValue: true, 891ConstantValue.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)
976=> operation.ConstantValue.HasValue && operation.ConstantValue.Value is null;
Microsoft.CodeAnalysis.Features (26)
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)
139value.ConstantValue.HasValue && 140value.ConstantValue.Value is string stringValue)
src\Analyzers\Core\Analyzers\RemoveUnusedMembers\AbstractRemoveUnusedMembersDiagnosticAnalyzer.cs (1)
311if (!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)
90if (invocation.Arguments[0].Value is ILiteralOperation { ConstantValue: { HasValue: true, Value: string value } } literal && 211? alignmentOp is { ConstantValue.HasValue: true } 248=> argument.Value.ConstantValue is { HasValue: true, Value: ' ' };
src\Analyzers\Core\Analyzers\UseConditionalExpression\UseConditionalExpressionHelpers.cs (1)
105=> trueValue is ILiteralOperation { ConstantValue: { HasValue: true, Value: bool value } } && value == val;
src\Analyzers\Core\Analyzers\UseThrowExpression\AbstractUseThrowExpressionDiagnosticAnalyzer.cs (2)
265return operation.ConstantValue.HasValue && 266operation.ConstantValue.Value == 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)
149if (current.BranchValue.ConstantValue.HasValue && current.BranchValue.ConstantValue.Value is bool constant)
Microsoft.CodeAnalysis.Workspaces (9)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\OperationExtensions.cs (1)
378=> operand is ILiteralOperation { ConstantValue: { HasValue: true, Value: null } };
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\CustomDataFlowAnalysis.cs (2)
149if (current.BranchValue.ConstantValue.HasValue && current.BranchValue.ConstantValue.Value is bool constant)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\FlowAnalysis\SymbolUsageAnalysis\SymbolUsageAnalysis.Walker.cs (1)
485if (currentOperation.ConstantValue.Value is null)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Extensions\SyntaxGeneratorExtensions_Negate.cs (5)
440var numericValue = numericLiteralExpression.ConstantValue; 479if (operation?.Kind == OperationKind.Literal && operation.ConstantValue.HasValue && operation.ConstantValue.Value is true) 483else 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)
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);