131 references to GetConstantValue
Microsoft.CodeAnalysis.CodeStyle (2)
src\Analyzers\Core\Analyzers\SimplifyBooleanExpression\AbstractSimplifyConditionalDiagnosticAnalyzer.cs (1)
164var constantValue = semanticModel.GetConstantValue(node, cancellationToken);
src\Analyzers\Core\Analyzers\UseCompoundAssignment\AbstractUseCompoundAssignmentDiagnosticAnalyzer.cs (1)
145var constant = semanticModel.GetConstantValue(binaryRight, cancellationToken).Value;
Microsoft.CodeAnalysis.CSharp.CodeStyle (10)
src\Analyzers\CSharp\Analyzers\UseCollectionExpression\UseCollectionExpressionHelpers.cs (4)
410semanticModel.GetConstantValue(size, cancellationToken).Value is 0) 625=> semanticModel.GetConstantValue(expression, cancellationToken).HasValue && 767if (semanticModel.GetConstantValue(size, cancellationToken).Value is not int sizeValue) 823if (semanticModel.GetConstantValue(elementArgument.Expression, cancellationToken).Value is not int indexValue ||
src\Analyzers\CSharp\Analyzers\UseNameofInNullableAttribute\CSharpUseNameofInNullableAttributeDiagnosticAnalyzer.cs (1)
87var constantValue = semanticModel.GetConstantValue(argument.Expression, cancellationToken);
src\Analyzers\CSharp\Analyzers\UsePatternMatching\CSharpAsAndMemberAccessDiagnosticAnalyzer.cs (3)
96var constantValue = semanticModel.GetConstantValue(binaryExpression.Right, cancellationToken); 139var constantValue = semanticModel.GetConstantValue(expression1, cancellationToken); 153var constantValue = semanticModel.GetConstantValue(expression2, cancellationToken);
src\Analyzers\CSharp\Analyzers\UseSimpleUsingStatement\UseSimpleUsingStatementDiagnosticAnalyzer.cs (1)
268var constantValue = semanticModel.GetConstantValue(returnStatement.Expression, cancellationToken);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (1)
144var constantValue = semanticModel.GetConstantValue(child, cancellationToken);
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (1)
src\Analyzers\CSharp\CodeFixes\ReplaceDefaultLiteral\CSharpReplaceDefaultLiteralCodeFixProvider.cs (1)
100else if (semanticModel.GetConstantValue(defaultLiteral, cancellationToken) is var constant && constant.HasValue)
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (1)
CodeGeneration\SyntaxGeneratorTests.cs (1)
94var constantValue = speculativeModel.GetConstantValue(replacement.Expression);
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (2)
CodeGen\CodeGenTupleEqualityTests.cs (2)
692Assert.False(model.GetConstantValue(tuple2).HasValue); 693Assert.Equal(1, model.GetConstantValue(tuple2.Arguments[1].Expression).Value);
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (2)
FieldKeywordTests.cs (1)
9479return (model.GetConstantValue(value).Value, typeInfo.Type.ToTestDisplayString(), typeInfo.ConvertedType.ToTestDisplayString());
Semantics\PatternMatchingTests.cs (1)
6577Assert.False(model.GetConstantValue(caseDefault.Pattern).HasValue);
Microsoft.CodeAnalysis.CSharp.Features (14)
CodeRefactorings\UseRecursivePatterns\UseRecursivePatternsCodeRefactoringProvider.cs (2)
373var (left, right) when model.GetConstantValue(left).HasValue => (right, left, Flipped: true), 374var (left, right) when model.GetConstantValue(right).HasValue => (left, right, Flipped: false),
ReverseForStatement\CSharpReverseForStatementCodeRefactoringProvider.cs (2)
92var startValue = semanticModel.GetConstantValue(start, cancellationToken); 93var endValue = semanticModel.GetConstantValue(end, cancellationToken);
src\Analyzers\CSharp\Analyzers\UseCollectionExpression\UseCollectionExpressionHelpers.cs (4)
410semanticModel.GetConstantValue(size, cancellationToken).Value is 0) 625=> semanticModel.GetConstantValue(expression, cancellationToken).HasValue && 767if (semanticModel.GetConstantValue(size, cancellationToken).Value is not int sizeValue) 823if (semanticModel.GetConstantValue(elementArgument.Expression, cancellationToken).Value is not int indexValue ||
src\Analyzers\CSharp\Analyzers\UseNameofInNullableAttribute\CSharpUseNameofInNullableAttributeDiagnosticAnalyzer.cs (1)
87var constantValue = semanticModel.GetConstantValue(argument.Expression, cancellationToken);
src\Analyzers\CSharp\Analyzers\UsePatternMatching\CSharpAsAndMemberAccessDiagnosticAnalyzer.cs (3)
96var constantValue = semanticModel.GetConstantValue(binaryExpression.Right, cancellationToken); 139var constantValue = semanticModel.GetConstantValue(expression1, cancellationToken); 153var constantValue = semanticModel.GetConstantValue(expression2, cancellationToken);
src\Analyzers\CSharp\Analyzers\UseSimpleUsingStatement\UseSimpleUsingStatementDiagnosticAnalyzer.cs (1)
268var constantValue = semanticModel.GetConstantValue(returnStatement.Expression, cancellationToken);
src\Analyzers\CSharp\CodeFixes\ReplaceDefaultLiteral\CSharpReplaceDefaultLiteralCodeFixProvider.cs (1)
100else if (semanticModel.GetConstantValue(defaultLiteral, cancellationToken) is var constant && constant.HasValue)
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (33)
Semantics\ConstantTests.cs (1)
2925var constantValue = comp.GetSemanticModel(tree).GetConstantValue(expr);
Semantics\ImplicitObjectCreationTests.cs (8)
243Assert.Equal(constant, model.GetConstantValue(@new).Value?.ToString()); 1872Assert.False(model.GetConstantValue(def).HasValue); 1902Assert.False(model.GetConstantValue(def).HasValue); 1932Assert.False(model.GetConstantValue(def).HasValue); 2043Assert.False(model.GetConstantValue(@new).HasValue); 2078Assert.False(model.GetConstantValue(@new).HasValue); 2224Assert.False(model.GetConstantValue(def).HasValue); 2572Assert.False(model.GetConstantValue(def).HasValue);
Semantics\LambdaTests.cs (1)
8061var constantValue = model.GetConstantValue(equalsValue.Value);
Semantics\NullableReferenceTypesTests.cs (2)
1869Assert.Equal(3, model.GetConstantValue(suppressions[0]).Value); 1870Assert.Null(model.GetConstantValue(suppressions[1]).Value);
Semantics\TargetTypedDefaultTests.cs (21)
48Assert.Equal("0", model.GetConstantValue(def).Value.ToString()); 148Assert.Equal("0", model.GetConstantValue(def).Value.ToString()); 249Assert.True(model.GetConstantValue(def).HasValue); 286Assert.True(model.GetConstantValue(def).HasValue); 525Assert.False(model.GetConstantValue(def).HasValue); 571Assert.False(model.GetConstantValue(def).HasValue); 614Assert.False(model.GetConstantValue(def).HasValue); 672Assert.False(model.GetConstantValue(def).HasValue); 753Assert.False(model.GetConstantValue(def).HasValue); 841Assert.False(model.GetConstantValue(def).HasValue); 870Assert.False(model.GetConstantValue(def).HasValue); 1147Assert.Equal("0", model.GetConstantValue(def).Value.ToString()); 3059Assert.False(model.GetConstantValue(def).HasValue); 3521Assert.Equal((short)0, model.GetConstantValue(def).Value); 3528Assert.Equal((short)0, model.GetConstantValue(conversionSyntax).Value); 3579Assert.False(model.GetConstantValue(default1).HasValue); 3587Assert.False(model.GetConstantValue(default2).HasValue); 3594Assert.False(model.GetConstantValue(default3).HasValue); 3601Assert.True(model.GetConstantValue(default4).HasValue); 3677Assert.False(model.GetConstantValue(value).HasValue); 3718Assert.False(model.GetConstantValue(defaultValue).HasValue);
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (48)
Compilation\GetSemanticInfoTests.cs (2)
2737Assert.False(model.GetConstantValue(expr).HasValue); 2808Assert.False(model.GetConstantValue(expr).HasValue);
Compilation\SemanticModelAPITests.cs (38)
1437var constantInfo = speculativeModel.GetConstantValue(expr); 1475var constantInfo = speculativeModel.GetConstantValue(expr); 1523var constantInfo = speculativeModel.GetConstantValue(expr); 1611var constantInfo = speculativeModel.GetConstantValue(expr); 1696var constantInfo = speculativeModel.GetConstantValue(expr); 2785var constantVal = speculativeModel.GetConstantValue(switchLabel.Value); 3912var value0 = model.GetConstantValue(init0); 3921var value1 = model.GetConstantValue(init1); 3928var value2 = model.GetConstantValue(init2); 4108Assert.True(model.GetConstantValue(actual[0]).HasValue); 4109Assert.Equal("Hello, world!", model.GetConstantValue(actual[0]).Value); 4110Assert.False(model.GetConstantValue(actual[1]).HasValue); 4146Assert.Equal("Number 3", model.GetConstantValue(actual[0]).Value); 4149Assert.Equal("Level 5 Number 3", model.GetConstantValue(actual[1]).Value); 4151Assert.False(model.GetConstantValue(actual[2]).HasValue); 4154Assert.Equal("Testing", model.GetConstantValue(actual[3]).Value); 4157Assert.Equal("ConstantInterpolatedString", model.GetConstantValue(actual[4]).Value); 4160Assert.Equal("Level 5", model.GetConstantValue(actual[5]).Value); 4163Assert.Equal("Radio Noise", model.GetConstantValue(actual[6]).Value); 4166Assert.Equal("Level 5", model.GetConstantValue(actual[7]).Value); 4188Assert.True(model.GetConstantValue(actual[0]).HasValue); 4189Assert.Equal("Hello, world!", model.GetConstantValue(actual[0]).Value); 4191Assert.False(model.GetConstantValue(actual[1]).HasValue); 4213Assert.True(model.GetConstantValue(actual[0]).HasValue); 4214Assert.Equal(0, model.GetConstantValue(actual[0]).Value); 4217Assert.True(model.GetConstantValue(actual[1]).HasValue); 4218Assert.Equal(true, model.GetConstantValue(actual[1]).Value); 4241Assert.True(model.GetConstantValue(actual[0]).HasValue); 4242Assert.Null(model.GetConstantValue(actual[0]).Value); 4279Assert.Equal("Number 3", model.GetConstantValue(actual[0]).Value); 4283Assert.Equal("Level 5 Number 3", model.GetConstantValue(actual[1]).Value); 4286Assert.False(model.GetConstantValue(actual[2]).HasValue); 4290Assert.Equal("Testing", model.GetConstantValue(actual[3]).Value); 4294Assert.Equal("ConstantInterpolatedString", model.GetConstantValue(actual[4]).Value); 4298Assert.Equal("Level 5", model.GetConstantValue(actual[5]).Value); 4302Assert.Equal("Radio Noise", model.GetConstantValue(actual[6]).Value); 4306Assert.Equal("Level 5", model.GetConstantValue(actual[7]).Value); 4460Assert.Equal("DEBUG", model.GetConstantValue(root.DescendantNodes().OfType<InvocationExpressionSyntax>().Single()));
Compilation\SemanticModelGetDeclaredSymbolAPITests.cs (6)
4275var constantInfo = speculativeModel.GetConstantValue(attr2.ArgumentList.Arguments.First().Expression); 4290constantInfo = speculativeModel.GetConstantValue(attr3.ArgumentList.Arguments.First().Expression); 4336constantInfo = speculativeModel.GetConstantValue(attr6.ArgumentList.Arguments.First().Expression); 4359constantInfo = speculativeModel.GetConstantValue(attr7.ArgumentList.Arguments.First().Expression); 4381constantInfo = speculativeModel.GetConstantValue(attr8.ArgumentList.Arguments.First().Expression); 5664Optional<object> actualConstant = model.GetConstantValue(valueSyntax);
Compilation\SemanticModelGetSemanticInfoTests.cs (1)
1668Assert.Throws<ArgumentNullException>(() => model.GetConstantValue((ExpressionSyntax)null));
Symbols\EnumTests.cs (1)
354var value = model.GetConstantValue(expr);
Microsoft.CodeAnalysis.CSharp.Test.Utilities (1)
CompilationTestUtils.cs (1)
236summary.ConstantValue = semanticModel.GetConstantValue(expr);
Microsoft.CodeAnalysis.CSharp.Workspaces (3)
Simplification\Simplifiers\AbstractCSharpSimplifier.cs (2)
265var nameofValueOpt = semanticModel.GetConstantValue(node.Parent.Parent.Parent); 386semanticModel.GetConstantValue(invocationExpr).HasValue &&
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Simplification\Simplifiers\CastSimplifier.cs (1)
144var constantValue = semanticModel.GetConstantValue(child, cancellationToken);
Microsoft.CodeAnalysis.Features (2)
EmbeddedLanguages\RegularExpressions\LanguageServices\RegexLanguageDetector.cs (1)
188var constVal = semanticModel.GetConstantValue(expr, cancellationToken);
src\Analyzers\Core\Analyzers\SimplifyBooleanExpression\AbstractSimplifyConditionalDiagnosticAnalyzer.cs (1)
164var constantValue = semanticModel.GetConstantValue(node, cancellationToken);
Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests (8)
Compilation\SemanticModelAPITests.vb (8)
622Dim initializerConstantVal = speculativeModel.GetConstantValue(speculatedExpression) 675Dim constantInfo = speculativeModel.GetConstantValue(expression) 728Dim constantInfo = speculativeModel.GetConstantValue(expression) 1249Dim constantInfo = speculativeModel.GetConstantValue(argument) 1266constantInfo = speculativeModel.GetConstantValue(argument) 1314constantInfo = speculativeModel.GetConstantValue(argument) 1350constantInfo = speculativeModel.GetConstantValue(argument) 1740Dim constantInfo = speculativeModel.GetConstantValue(speculatedTypeSyntax)
Microsoft.CodeAnalysis.VisualBasic.Workspaces (1)
Simplification\Simplifiers\AbstractVisualBasicSimplifier.vb (1)
156Dim nameofValueOpt = semanticModel.GetConstantValue(node.Parent.Parent.Parent)
Microsoft.Maui.Controls.BindingSourceGen (1)
PathParser.cs (1)
184 object? indexValue = _context.SemanticModel.GetConstantValue(indexExpression).Value;
Microsoft.VisualStudio.LanguageServices.VisualBasic (2)
CodeModel\MethodXML\MethodXmlBuilder.vb (2)
232Dim constantValue = SemanticModel.GetConstantValue(expression) 528Dim constantValue = SemanticModel.GetConstantValue(expression)