1 instantiation of SwitchSectionSyntax
Microsoft.CodeAnalysis.CSharp (1)
Syntax.xml.Internal.Generated.cs (1)
13849internal override SyntaxNode CreateRed(SyntaxNode? parent, int position) => new CSharp.Syntax.SwitchSectionSyntax(this, parent, position);
131 references to SwitchSectionSyntax
Microsoft.CodeAnalysis.CSharp (34)
Binder\ExpressionVariableFinder.cs (1)
137public override void VisitSwitchSection(SwitchSectionSyntax node)
Binder\LocalBinderFactory.cs (2)
738foreach (SwitchSectionSyntax section in node.Sections) 744public override void VisitSwitchSection(SwitchSectionSyntax node)
Binder\SwitchBinder.cs (3)
138foreach (var section in SwitchSyntax.Sections) 150foreach (var section in SwitchSyntax.Sections) 180foreach (var section in SwitchSyntax.Sections)
Binder\SwitchBinder_Patterns.cs (2)
168foreach (SwitchSectionSyntax sectionSyntax in SwitchSyntax.Sections) 181SwitchSectionSyntax node,
Compilation\MemberSemanticModel.cs (1)
296if (LookupPosition.IsInSwitchSectionScope(position, (SwitchSectionSyntax)current))
FlowAnalysis\AbstractFlowPass_Switch.cs (1)
106foreach (var sectionSyntax in ((SwitchStatementSyntax)node.Syntax).Sections)
Syntax.xml.Main.Generated.cs (7)
436public virtual TResult? VisitSwitchSection(SwitchSectionSyntax node) => this.DefaultVisit(node); 1180public virtual void VisitSwitchSection(SwitchSectionSyntax node) => this.DefaultVisit(node); 1923public override SyntaxNode? VisitSwitchSection(SwitchSectionSyntax node) 4557public static SwitchStatementSyntax SwitchStatement(SyntaxList<AttributeListSyntax> attributeLists, SyntaxToken switchKeyword, SyntaxToken openParenToken, ExpressionSyntax expression, SyntaxToken closeParenToken, SyntaxToken openBraceToken, SyntaxList<SwitchSectionSyntax> sections, SyntaxToken closeBraceToken) 4579public static SwitchSectionSyntax SwitchSection(SyntaxList<SwitchLabelSyntax> labels, SyntaxList<StatementSyntax> statements) 4581return (SwitchSectionSyntax)Syntax.InternalSyntax.SyntaxFactory.SwitchSection(labels.Node.ToGreenList<Syntax.InternalSyntax.SwitchLabelSyntax>(), statements.Node.ToGreenList<Syntax.InternalSyntax.StatementSyntax>()).CreateRed(); 4585public static SwitchSectionSyntax SwitchSection()
Syntax.xml.Syntax.Generated.cs (11)
8503public SyntaxList<SwitchSectionSyntax> Sections => new SyntaxList<SwitchSectionSyntax>(GetRed(ref this.sections, 6)); 8531public SwitchStatementSyntax Update(SyntaxList<AttributeListSyntax> attributeLists, SyntaxToken switchKeyword, SyntaxToken openParenToken, ExpressionSyntax expression, SyntaxToken closeParenToken, SyntaxToken openBraceToken, SyntaxList<SwitchSectionSyntax> sections, SyntaxToken closeBraceToken) 8550public SwitchStatementSyntax WithSections(SyntaxList<SwitchSectionSyntax> sections) => Update(this.AttributeLists, this.SwitchKeyword, this.OpenParenToken, this.Expression, this.CloseParenToken, this.OpenBraceToken, sections, this.CloseBraceToken); 8555public SwitchStatementSyntax AddSections(params SwitchSectionSyntax[] items) => WithSections(this.Sections.AddRange(items)); 8604public SwitchSectionSyntax Update(SyntaxList<SwitchLabelSyntax> labels, SyntaxList<StatementSyntax> statements) 8608var newNode = SyntaxFactory.SwitchSection(labels, statements); 8616public SwitchSectionSyntax WithLabels(SyntaxList<SwitchLabelSyntax> labels) => Update(labels, this.Statements); 8617public SwitchSectionSyntax WithStatements(SyntaxList<StatementSyntax> statements) => Update(this.Labels, statements); 8619public SwitchSectionSyntax AddLabels(params SwitchLabelSyntax[] items) => WithLabels(this.Labels.AddRange(items)); 8620public SwitchSectionSyntax AddStatements(params StatementSyntax[] items) => WithStatements(this.Statements.AddRange(items));
Syntax\LookupPosition.cs (1)
282internal static bool IsInSwitchSectionScope(int position, SwitchSectionSyntax section)
Syntax\SwitchStatementSyntax.cs (2)
11public SwitchStatementSyntax Update(SyntaxToken switchKeyword, SyntaxToken openParenToken, ExpressionSyntax expression, SyntaxToken closeParenToken, SyntaxToken openBraceToken, SyntaxList<SwitchSectionSyntax> sections, SyntaxToken closeBraceToken) 20public static SwitchStatementSyntax SwitchStatement(SyntaxToken switchKeyword, SyntaxToken openParenToken, ExpressionSyntax expression, SyntaxToken closeParenToken, SyntaxToken openBraceToken, SyntaxList<SwitchSectionSyntax> sections, SyntaxToken closeBraceToken)
Syntax\SyntaxFactory.cs (2)
2730public static SwitchStatementSyntax SwitchStatement(ExpressionSyntax expression, SyntaxList<SwitchSectionSyntax> sections) 2749return SyntaxFactory.SwitchStatement(expression, default(SyntaxList<SwitchSectionSyntax>));
Syntax\SyntaxNormalizer.cs (1)
1391node is SwitchSectionSyntax ||
Microsoft.CodeAnalysis.CSharp.CodeStyle (9)
src\Analyzers\CSharp\Analyzers\ConvertSwitchStatementToExpression\ConvertSwitchStatementToExpressionDiagnosticAnalyzer.Analyzer.cs (1)
219private SyntaxKind AnalyzeSwitchSection(SwitchSectionSyntax section)
src\Analyzers\CSharp\Analyzers\RemoveUnreachableCode\RemoveUnreachableCodeHelpers.cs (1)
22case SwitchSectionSyntax switchSection:
src\Analyzers\CSharp\Analyzers\RemoveUnusedParametersAndValues\CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs (1)
70return statementAncestor is not (BlockSyntax or SwitchSectionSyntax);
src\Analyzers\CSharp\Analyzers\UsePatternMatching\CSharpAsAndNullCheckDiagnosticAnalyzer.cs (1)
113if (enclosingBlock is not BlockSyntax and not SwitchSectionSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\IndentBlockFormattingRule.cs (1)
76if (node is not SwitchSectionSyntax section)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\SuppressFormattingRule.cs (1)
184if (node is SwitchSectionSyntax switchSection)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\WrappingFormattingRule.cs (1)
82SwitchSectionSyntax switchSection => (switchSection.GetFirstToken(includeZeroWidth: true), switchSection.GetLastToken(includeZeroWidth: true)),
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpBlockFacts.cs (2)
31SwitchSectionSyntax switchSection => switchSection, 41SwitchSectionSyntax switchSection => switchSection.Statements,
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (14)
src\Analyzers\CSharp\CodeFixes\AssignOutParameters\AbstractAssignOutParametersCodeFixProvider.cs (1)
68|| location.Parent is SwitchSectionSyntax
src\Analyzers\CSharp\CodeFixes\AssignOutParameters\AssignOutParametersAboveReturnCodeFixProvider.cs (1)
65else if (parent is BlockSyntax or SwitchSectionSyntax)
src\Analyzers\CSharp\CodeFixes\ConvertSwitchStatementToExpression\ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.cs (1)
122private SwitchExpressionArmSyntax GetSwitchExpressionArm(SwitchSectionSyntax node)
src\Analyzers\CSharp\CodeFixes\PopulateSwitch\CSharpPopulateSwitchStatementCodeFixProvider.cs (1)
19: AbstractPopulateSwitchStatementCodeFixProvider<SwitchStatementSyntax, SwitchSectionSyntax, MemberAccessExpressionSyntax>;
src\Analyzers\CSharp\CodeFixes\RemoveUnusedParametersAndValues\CSharpRemoveUnusedValuesCodeFixProvider.cs (2)
30ForEachStatementSyntax, SwitchSectionSyntax, SwitchLabelSyntax, CatchClauseSyntax, CatchClauseSyntax> 168protected override void InsertAtStartOfSwitchCaseBlockForDeclarationInCaseLabelOrClause(SwitchSectionSyntax switchCaseBlock, SyntaxEditor editor, LocalDeclarationStatementSyntax declarationStatement)
src\Analyzers\CSharp\CodeFixes\UsePatternMatching\CSharpAsAndNullCheckCodeFixProvider.cs (2)
65: ((SwitchSectionSyntax)newParentScope).Statements.First(); 75if (statement.Parent is BlockSyntax or SwitchSectionSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTokenExtensions.cs (2)
412var section = targetToken.GetAncestor<SwitchSectionSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (1)
1557if (node is CaseSwitchLabelSyntax { Parent: SwitchSectionSyntax })
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Indentation\CSharpIndentationService.cs (1)
174if (node is not SwitchSectionSyntax { Statements: [var firstStatement, ..] and [.., var lastStatement] })
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpReplaceDiscardDeclarationsWithAssignmentsService.cs (1)
208if (_localDeclarationStatement.Parent is BlockSyntax or SwitchSectionSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpTypeInferenceService.TypeInferrer.cs (1)
2211var container = afterNode.AncestorsAndSelf().FirstOrDefault(a => a is BlockSyntax or SwitchSectionSyntax);
Microsoft.CodeAnalysis.CSharp.Features (38)
ConvertIfToSwitch\CSharpConvertIfToSwitchCodeRefactoringProvider.Rewriting.cs (1)
77[.. sectionList.Cast<SwitchSectionSyntax>()],
Debugging\CSharpProximityExpressionsService.Worker.cs (1)
272foreach (var section in switchStatement.Sections)
EditAndContinue\BreakpointSpans.cs (1)
556if (switchLabel.Parent is not SwitchSectionSyntax switchSection || switchSection.Statements.Count == 0)
EditAndContinue\CSharpEditAndContinueAnalyzer.cs (3)
1805return ((SwitchSectionSyntax)node).Labels.Last().Span; 2912private static bool AreSwitchSectionsEquivalent(SwitchSectionSyntax oldSection, SwitchSectionSyntax newSection)
EditAndContinue\SyntaxComparer.cs (4)
742return Equal((SwitchSectionSyntax)left, (SwitchSectionSyntax)right); 764private bool Equal(SwitchSectionSyntax left, SwitchSectionSyntax right)
ExtractMethod\CSharpMethodExtractor.CSharpCodeGenerator.CallSiteContainerRewriter.cs (1)
134public override SyntaxNode VisitSwitchSection(SwitchSectionSyntax node)
ExtractMethod\CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs (1)
74SwitchSectionSyntax switchSectionNode => switchSectionNode.Statements,
ExtractMethod\Extensions.cs (1)
39=> node is BlockSyntax or SwitchSectionSyntax or GlobalStatementSyntax;
Highlighting\KeywordHighlighters\SwitchStatementHighlighter.cs (1)
41foreach (var switchSection in switchStatement.Sections)
IntroduceUsingStatement\CSharpIntroduceUsingStatementCodeRefactoringProvider.cs (4)
42=> parent is BlockSyntax or SwitchSectionSyntax || parent.IsEmbeddedStatementOwner(); 48SwitchSectionSyntax switchSection => switchSection.Statements, 56parentOfStatementsToSurround is SwitchSectionSyntax switchSection ? switchSection.WithStatements(statements) : 99if (declarationStatement.Parent is SwitchSectionSyntax ||
IntroduceVariable\CSharpIntroduceVariableService_IntroduceLocal.cs (3)
530private static bool IsBlockLike(SyntaxNode node) => node is BlockSyntax or SwitchSectionSyntax; 536SwitchSectionSyntax switchSection => switchSection.Statements, 544SwitchSectionSyntax switchSection => switchSection.WithStatements(statements),
InvertIf\CSharpInvertIfCodeRefactoringProvider.cs (4)
70case SwitchSectionSyntax: 89SwitchSectionSyntax n => n.Statements, 96SwitchSectionSyntax 227SwitchSectionSyntax n => n.WithStatements([.. statements]),
src\Analyzers\CSharp\Analyzers\ConvertSwitchStatementToExpression\ConvertSwitchStatementToExpressionDiagnosticAnalyzer.Analyzer.cs (1)
219private SyntaxKind AnalyzeSwitchSection(SwitchSectionSyntax section)
src\Analyzers\CSharp\Analyzers\RemoveUnreachableCode\RemoveUnreachableCodeHelpers.cs (1)
22case SwitchSectionSyntax switchSection:
src\Analyzers\CSharp\Analyzers\RemoveUnusedParametersAndValues\CSharpRemoveUnusedParametersAndValuesDiagnosticAnalyzer.cs (1)
70return statementAncestor is not (BlockSyntax or SwitchSectionSyntax);
src\Analyzers\CSharp\Analyzers\UsePatternMatching\CSharpAsAndNullCheckDiagnosticAnalyzer.cs (1)
113if (enclosingBlock is not BlockSyntax and not SwitchSectionSyntax)
src\Analyzers\CSharp\CodeFixes\AssignOutParameters\AbstractAssignOutParametersCodeFixProvider.cs (1)
68|| location.Parent is SwitchSectionSyntax
src\Analyzers\CSharp\CodeFixes\AssignOutParameters\AssignOutParametersAboveReturnCodeFixProvider.cs (1)
65else if (parent is BlockSyntax or SwitchSectionSyntax)
src\Analyzers\CSharp\CodeFixes\ConvertSwitchStatementToExpression\ConvertSwitchStatementToExpressionCodeFixProvider.Rewriter.cs (1)
122private SwitchExpressionArmSyntax GetSwitchExpressionArm(SwitchSectionSyntax node)
src\Analyzers\CSharp\CodeFixes\PopulateSwitch\CSharpPopulateSwitchStatementCodeFixProvider.cs (1)
19: AbstractPopulateSwitchStatementCodeFixProvider<SwitchStatementSyntax, SwitchSectionSyntax, MemberAccessExpressionSyntax>;
src\Analyzers\CSharp\CodeFixes\RemoveUnusedParametersAndValues\CSharpRemoveUnusedValuesCodeFixProvider.cs (2)
30ForEachStatementSyntax, SwitchSectionSyntax, SwitchLabelSyntax, CatchClauseSyntax, CatchClauseSyntax> 168protected override void InsertAtStartOfSwitchCaseBlockForDeclarationInCaseLabelOrClause(SwitchSectionSyntax switchCaseBlock, SyntaxEditor editor, LocalDeclarationStatementSyntax declarationStatement)
src\Analyzers\CSharp\CodeFixes\UsePatternMatching\CSharpAsAndNullCheckCodeFixProvider.cs (2)
65: ((SwitchSectionSyntax)newParentScope).Statements.First(); 75if (statement.Parent is BlockSyntax or SwitchSectionSyntax)
Structure\Providers\SwitchStatementStructureProvider.cs (1)
28foreach (var section in node.Sections)
Microsoft.CodeAnalysis.CSharp.IOperation.UnitTests (1)
IOperation\IOperationTests_IParameterReferenceExpression.cs (1)
870VerifyOperationTreeAndDiagnosticsForTest<SwitchSectionSyntax>(source, expectedOperationTree, expectedDiagnostics);
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (2)
Semantics\NullableReferenceTypesTests.cs (2)
161378var sections = syntaxTree.GetRoot().DescendantNodes().OfType<SwitchSectionSyntax>().ToImmutableArray(); 161380var unreachableSection = sections[^1];
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (7)
Generated\Syntax.Test.xml.Generated.cs (6)
10778=> SyntaxFactory.SwitchStatement(new SyntaxList<AttributeListSyntax>(), SyntaxFactory.Token(SyntaxKind.SwitchKeyword), default(SyntaxToken), GenerateIdentifierName(), default(SyntaxToken), SyntaxFactory.Token(SyntaxKind.OpenBraceToken), new SyntaxList<SwitchSectionSyntax>(), SyntaxFactory.Token(SyntaxKind.CloseBraceToken)); 10780private static SwitchSectionSyntax GenerateSwitchSection() 12811var node = GenerateSwitchSection(); 12815var newNode = node.WithLabels(node.Labels).WithStatements(node.Statements); 17903var oldNode = GenerateSwitchSection(); 17919var oldNode = GenerateSwitchSection();
Syntax\SyntaxTests.cs (1)
163var section = SyntaxFactory.SwitchSection();
Microsoft.CodeAnalysis.CSharp.Workspaces (15)
CodeGeneration\CSharpSyntaxGenerator.cs (3)
2335var newSections = statement.Sections.InsertRange(index, switchSections.Cast<SwitchSectionSyntax>()); 3609[.. caseClauses.Cast<SwitchSectionSyntax>()]); 3619[.. caseClauses.Cast<SwitchSectionSyntax>()],
ReassignedVariable\CSharpReassignedVariableService.cs (1)
44if (current is BlockSyntax or SwitchSectionSyntax or ArrowExpressionClauseSyntax or AnonymousMethodExpressionSyntax or MemberDeclarationSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\IndentBlockFormattingRule.cs (1)
76if (node is not SwitchSectionSyntax section)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\SuppressFormattingRule.cs (1)
184if (node is SwitchSectionSyntax switchSection)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\WrappingFormattingRule.cs (1)
82SwitchSectionSyntax switchSection => (switchSection.GetFirstToken(includeZeroWidth: true), switchSection.GetLastToken(includeZeroWidth: true)),
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpBlockFacts.cs (2)
31SwitchSectionSyntax switchSection => switchSection, 41SwitchSectionSyntax switchSection => switchSection.Statements,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTokenExtensions.cs (2)
412var section = targetToken.GetAncestor<SwitchSectionSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (1)
1557if (node is CaseSwitchLabelSyntax { Parent: SwitchSectionSyntax })
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Indentation\CSharpIndentationService.cs (1)
174if (node is not SwitchSectionSyntax { Statements: [var firstStatement, ..] and [.., var lastStatement] })
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpReplaceDiscardDeclarationsWithAssignmentsService.cs (1)
208if (_localDeclarationStatement.Parent is BlockSyntax or SwitchSectionSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpTypeInferenceService.TypeInferrer.cs (1)
2211var container = afterNode.AncestorsAndSelf().FirstOrDefault(a => a is BlockSyntax or SwitchSectionSyntax);
Roslyn.Diagnostics.CSharp.Analyzers (11)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\IndentBlockFormattingRule.cs (1)
76if (node is not SwitchSectionSyntax section)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\SuppressFormattingRule.cs (1)
184if (node is SwitchSectionSyntax switchSection)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Formatting\Rules\WrappingFormattingRule.cs (1)
82SwitchSectionSyntax switchSection => (switchSection.GetFirstToken(includeZeroWidth: true), switchSection.GetLastToken(includeZeroWidth: true)),
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Services\SyntaxFacts\CSharpBlockFacts.cs (2)
31SwitchSectionSyntax switchSection => switchSection, 41SwitchSectionSyntax switchSection => switchSection.Statements,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTokenExtensions.cs (2)
412var section = targetToken.GetAncestor<SwitchSectionSyntax>();
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Extensions\ContextQuery\SyntaxTreeExtensions.cs (1)
1557if (node is CaseSwitchLabelSyntax { Parent: SwitchSectionSyntax })
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\Indentation\CSharpIndentationService.cs (1)
174if (node is not SwitchSectionSyntax { Statements: [var firstStatement, ..] and [.., var lastStatement] })
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpReplaceDiscardDeclarationsWithAssignmentsService.cs (1)
208if (_localDeclarationStatement.Parent is BlockSyntax or SwitchSectionSyntax)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\CSharp\LanguageServices\CSharpTypeInferenceService.TypeInferrer.cs (1)
2211var container = afterNode.AncestorsAndSelf().FirstOrDefault(a => a is BlockSyntax or SwitchSectionSyntax);