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