176 references to GetConstantValue
Microsoft.CodeAnalysis.CodeStyle (2)
AbstractSimplifyConditionalDiagnosticAnalyzer.cs (1)
163var constantValue = semanticModel.GetConstantValue(node, cancellationToken);
AbstractUseCompoundAssignmentDiagnosticAnalyzer.cs (1)
141var constant = semanticModel.GetConstantValue(binaryRight, cancellationToken).Value;
Microsoft.CodeAnalysis.CSharp.CodeStyle (6)
CastSimplifier.cs (1)
137var constantValue = semanticModel.GetConstantValue(child, cancellationToken);
CSharpAsAndMemberAccessDiagnosticAnalyzer.cs (3)
96var constantValue = semanticModel.GetConstantValue(binaryExpression.Right, cancellationToken); 139var constantValue = semanticModel.GetConstantValue(expression1, cancellationToken); 153var constantValue = semanticModel.GetConstantValue(expression2, cancellationToken);
CSharpUseNameofInNullableAttributeDiagnosticAnalyzer.cs (1)
84var constantValue = semanticModel.GetConstantValue(argument.Expression, cancellationToken);
UseSimpleUsingStatementDiagnosticAnalyzer.cs (1)
248var constantValue = semanticModel.GetConstantValue(returnStatement.Expression, cancellationToken);
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (1)
CSharpReplaceDefaultLiteralCodeFixProvider.cs (1)
105else if (semanticModel.GetConstantValue(defaultLiteral, cancellationToken) is var constant && constant.HasValue)
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (1)
CodeGeneration\SyntaxGeneratorTests.cs (1)
95var constantValue = speculativeModel.GetConstantValue(replacement.Expression);
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (2)
CodeGen\CodeGenTupleEqualityTests.cs (2)
713Assert.False(model.GetConstantValue(tuple2).HasValue); 714Assert.Equal(1, model.GetConstantValue(tuple2.Arguments[1].Expression).Value);
Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests (1)
Semantics\PatternMatchingTests.cs (1)
6575Assert.False(model.GetConstantValue(caseDefault.Pattern).HasValue);
Microsoft.CodeAnalysis.CSharp.Features (11)
CodeRefactorings\UseRecursivePatterns\UseRecursivePatternsCodeRefactoringProvider.cs (2)
355var (left, right) when model.GetConstantValue(left).HasValue => (right, left, Flipped: true), 356var (left, right) when model.GetConstantValue(right).HasValue => (left, right, Flipped: false),
CSharpAsAndMemberAccessDiagnosticAnalyzer.cs (3)
96var constantValue = semanticModel.GetConstantValue(binaryExpression.Right, cancellationToken); 139var constantValue = semanticModel.GetConstantValue(expression1, cancellationToken); 153var constantValue = semanticModel.GetConstantValue(expression2, cancellationToken);
CSharpReplaceDefaultLiteralCodeFixProvider.cs (1)
105else if (semanticModel.GetConstantValue(defaultLiteral, cancellationToken) is var constant && constant.HasValue)
CSharpUseNameofInNullableAttributeDiagnosticAnalyzer.cs (1)
84var constantValue = semanticModel.GetConstantValue(argument.Expression, cancellationToken);
QuickInfo\CSharpDiagnosticAnalyzerQuickInfoProvider.cs (1)
127var checkIdObject = semanticModel.GetConstantValue(suppressMessageCheckIdArgument.Expression, cancellationToken);
ReverseForStatement\CSharpReverseForStatementCodeRefactoringProvider.cs (2)
90var startValue = semanticModel.GetConstantValue(start, cancellationToken); 91var endValue = semanticModel.GetConstantValue(end, cancellationToken);
UseSimpleUsingStatementDiagnosticAnalyzer.cs (1)
248var constantValue = semanticModel.GetConstantValue(returnStatement.Expression, cancellationToken);
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)
8027var constantValue = model.GetConstantValue(equalsValue.Value);
Semantics\NullableReferenceTypesTests.cs (2)
1857Assert.Equal(3, model.GetConstantValue(suppressions[0]).Value); 1858Assert.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); 5294Optional<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)
CastSimplifier.cs (1)
137var constantValue = semanticModel.GetConstantValue(child, cancellationToken);
Simplification\Simplifiers\AbstractCSharpSimplifier.cs (2)
271var nameofValueOpt = semanticModel.GetConstantValue(node.Parent.Parent.Parent); 392semanticModel.GetConstantValue(invocationExpr).HasValue &&
Microsoft.CodeAnalysis.Features (10)
AbstractSimplifyConditionalDiagnosticAnalyzer.cs (1)
163var constantValue = semanticModel.GetConstantValue(node, cancellationToken);
AbstractUseCompoundAssignmentDiagnosticAnalyzer.cs (1)
141var constant = semanticModel.GetConstantValue(binaryRight, cancellationToken).Value;
Completion\Providers\AbstractInternalsVisibleToCompletionProvider.cs (1)
236var constantCandidate = semanticModel.GetConstantValue(constructorArgument, cancellationToken);
ConvertForToForEach\AbstractConvertForToForEachCodeRefactoringProvider.cs (2)
92var initializerValue = semanticModel.GetConstantValue(initializer, cancellationToken); 99var stepValue = semanticModel.GetConstantValue(stepValueExpressionOpt);
ConvertNumericLiteral\AbstractConvertNumericLiteralCodeRefactoringProvider.cs (1)
45var valueOpt = semanticModel.GetConstantValue(syntaxNode);
EmbeddedLanguages\Json\LanguageServices\JsonLanguageDetector.cs (2)
195semanticModel.GetConstantValue(initExpr).Value is true) 200semanticModel.GetConstantValue(initExpr).Value is (byte)JsonCommentHandling.Allow or (byte)JsonCommentHandling.Skip)
EmbeddedLanguages\RegularExpressions\LanguageServices\RegexLanguageDetector.cs (1)
210var constVal = semanticModel.GetConstantValue(expr, cancellationToken);
IntroduceVariable\AbstractIntroduceVariableService.State.cs (1)
217if (document.SemanticModel.GetConstantValue(expression, cancellationToken) is { HasValue: true, Value: var value })
Microsoft.CodeAnalysis.VisualBasic.CodeStyle (1)
SpeculationAnalyzer.vb (1)
562Me.SpeculativeSemanticModel.GetConstantValue(newExpression).HasValue Then
Microsoft.CodeAnalysis.VisualBasic.Emit.UnitTests (1)
Attributes\AttributeTests.vb (1)
2104Dim constantValue = comp.GetSemanticModel(tree).GetConstantValue(expr)
Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests (48)
Compilation\SemanticModelAPITests.vb (9)
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) 4587Assert.False(model.GetConstantValue(interp).HasValue)
Semantics\GetExtendedSemanticInfoTests.vb (1)
3288Return semanticModel.GetConstantValue(DirectCast(Nothing, ExpressionSyntax))
Semantics\NameOfTests.vb (36)
59Assert.Equal("MaxValue", model.GetConstantValue(node1).Value) 96Assert.Null(model.GetConstantValue(node2).Value) 124Assert.Equal("Variant", model.GetConstantValue(node3).Value) 456Assert.Equal("System", model.GetConstantValue(node1).Value) 528Assert.Equal("M1", model.GetConstantValue(node1).Value) 867Assert.Equal("C3", model.GetConstantValue(node1).Value) 944Assert.Equal("CC3", model.GetConstantValue(node1).Value) 1057Assert.Equal("CC3", model.GetConstantValue(node1).Value) 1125Assert.Equal("alias", model.GetConstantValue(node1).Value) 1190Assert.Equal("M1", model.GetConstantValue(node1).Value) 1272Assert.Equal("P1", model.GetConstantValue(node1).Value) 1354Assert.Equal("F1", model.GetConstantValue(node1).Value) 1435Assert.Equal("E1", model.GetConstantValue(node1).Value) 1515Assert.Equal("Missing", model.GetConstantValue(node1).Value) 1646Assert.Equal("Ambiguous", model.GetConstantValue(node1).Value) 1739Assert.Equal("LOCAL", model.GetConstantValue(node1).Value) 1796Assert.Equal("LOCAL", model.GetConstantValue(node1).Value) 1853Assert.Equal("LOCAL", model.GetConstantValue(node1).Value) 1910Assert.Equal("LOCAL", model.GetConstantValue(node1).Value) 2052Assert.Equal("F1", model.GetConstantValue(node1).Value) 2151Assert.Equal("P1", model.GetConstantValue(node1).Value) 2252Assert.Equal("M1", model.GetConstantValue(node1).Value) 2358Assert.Equal("M1", model.GetConstantValue(node1).Value) 2462Assert.Equal("E1", model.GetConstantValue(node1).Value) 2795Assert.Equal("MTest", model.GetConstantValue(node1).Value) 2870Assert.Equal("MTest", model.GetConstantValue(node1).Value) 2935Assert.Equal("MTest", model.GetConstantValue(node1).Value) 2998Assert.Equal("MTest", model.GetConstantValue(node1).Value) 3059Assert.Equal("MTest", model.GetConstantValue(node1).Value) 3120Assert.Equal("MTest", model.GetConstantValue(node1).Value) 3180Assert.Equal("MTest", model.GetConstantValue(node1).Value) 3243Assert.Equal("M1", model.GetConstantValue(node1).Value) 3304Assert.Equal("F1", model.GetConstantValue(node1).Value) 3361Assert.Equal("F1", model.GetConstantValue(node1).Value) 3420Assert.Equal("MTest", model.GetConstantValue(node1).Value) 3476Assert.Equal("MTest", model.GetConstantValue(node1).Value)
Semantics\TypeOfTests.vb (1)
796Assert.False(semantics.GetConstantValue(typeOfExpressions(5)).HasValue)
Semantics\WithBlockSemanticModelTests.vb (1)
40Assert.False(model.GetConstantValue(withExpression).HasValue)
Microsoft.CodeAnalysis.VisualBasic.Symbol.UnitTests (1)
SymbolsTests\Source\EnumTests.vb (1)
1451Dim value = model.GetConstantValue(expr)
Microsoft.CodeAnalysis.VisualBasic.Workspaces (2)
Simplification\Simplifiers\AbstractVisualBasicSimplifier.vb (1)
156Dim nameofValueOpt = semanticModel.GetConstantValue(node.Parent.Parent.Parent)
SpeculationAnalyzer.vb (1)
562Me.SpeculativeSemanticModel.GetConstantValue(newExpression).HasValue Then
Microsoft.VisualStudio.LanguageServices.CSharp (2)
CodeModel\MethodXml\MethodXmlBuilder.cs (2)
249var constantValue = SemanticModel.GetConstantValue(expression); 291var constantValue = SemanticModel.GetConstantValue(expression);
Microsoft.VisualStudio.LanguageServices.VisualBasic (2)
CodeModel\MethodXML\MethodXmlBuilder.vb (2)
232Dim constantValue = SemanticModel.GetConstantValue(expression) 528Dim constantValue = SemanticModel.GetConstantValue(expression)