Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
12f9859a
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
12f9859a
编写于
10月 14, 2019
作者:
A
Alireza Habibi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Attach the simplifier
上级
cdf4fd3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
32 deletion
+30
-32
src/EditorFeatures/CSharpTest/CodeActions/ConvertIfToSwitch/ConvertIfToSwitchTests.cs
...t/CodeActions/ConvertIfToSwitch/ConvertIfToSwitchTests.cs
+12
-12
src/Features/Core/Portable/ConvertIfToSwitch/AbstractConvertIfToSwitchCodeRefactoringProvider.Rewriting.cs
...ractConvertIfToSwitchCodeRefactoringProvider.Rewriting.cs
+18
-20
未找到文件。
src/EditorFeatures/CSharpTest/CodeActions/ConvertIfToSwitch/ConvertIfToSwitchTests.cs
浏览文件 @
12f9859a
...
...
@@ -341,7 +341,7 @@ void M(object o)
{
switch (o)
{
case string s when
(s.Length > 5 && s.Length < 10)
:
case string s when
s.Length > 5 && s.Length < 10
:
return;
case int i:
return;
...
...
@@ -985,7 +985,7 @@ void M(int i)
{
switch (i)
{
case 1 when i == 2 &&
(i == 3)
:
case 1 when i == 2 &&
i == 3
:
return;
case 10:
return;
...
...
@@ -1015,7 +1015,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2)
&& i == 3:
case 1 when
i == 2
&& i == 3:
return;
case 10:
return;
...
...
@@ -1045,7 +1045,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2) && (i == 3)
:
case 1 when
i == 2 && i == 3
:
return;
case 10:
return;
...
...
@@ -1105,7 +1105,7 @@ void M(int i)
{
switch (i)
{
case 1 when i == 2 &&
(i == 3)
:
case 1 when i == 2 &&
i == 3
:
return;
case 10:
return;
...
...
@@ -1135,7 +1135,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2)
&& i == 3:
case 1 when
i == 2
&& i == 3:
return;
case 10:
return;
...
...
@@ -1165,7 +1165,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2) && (i == 3)
:
case 1 when
i == 2 && i == 3
:
return;
case 10:
return;
...
...
@@ -1195,7 +1195,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2 && i == 3)
:
case 1 when
i == 2 && i == 3
:
return;
case 10:
return;
...
...
@@ -1285,7 +1285,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2)
&& i == 3:
case 1 when
i == 2
&& i == 3:
return;
case 10:
return;
...
...
@@ -1315,7 +1315,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2) && (i == 3)
:
case 1 when
i == 2 && i == 3
:
return;
case 10:
return;
...
...
@@ -1345,7 +1345,7 @@ void M(int i)
{
switch (i)
{
case 1 when
((i == 2) && i == 3)
:
case 1 when
i == 2 && i == 3
:
return;
case 10:
return;
...
...
@@ -1375,7 +1375,7 @@ void M(int i)
{
switch (i)
{
case 1 when
(i == 2 && (i == 3))
:
case 1 when
i == 2 && i == 3
:
return;
case 10:
return;
...
...
src/Features/Core/Portable/ConvertIfToSwitch/AbstractConvertIfToSwitchCodeRefactoringProvider.Rewriting.cs
浏览文件 @
12f9859a
...
...
@@ -9,6 +9,7 @@
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Editing
;
using
Microsoft.CodeAnalysis.Formatting
;
using
Microsoft.CodeAnalysis.Simplification
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.ConvertIfToSwitch
...
...
@@ -33,32 +34,29 @@ internal abstract partial class AbstractConvertIfToSwitchCodeRefactoringProvider
var
generator
=
SyntaxGenerator
.
GetGenerator
(
document
);
var
ifSpan
=
ifStatement
.
Span
;
SyntaxNode
@switch
;
if
(
convertToSwitchExpression
)
{
@switch
=
CreateSwitchExpressionStatement
(
target
,
sections
);
}
else
{
var
lastNode
=
sections
.
LastOrDefault
()?.
SyntaxToRemove
??
ifStatement
;
@switch
=
CreateSwitchStatement
(
ifStatement
,
target
,
sections
.
Select
(
AsSwitchSectionSyntax
))
.
WithLeadingTrivia
(
ifStatement
.
GetLeadingTrivia
())
.
WithTrailingTrivia
(
lastNode
.
GetTrailingTrivia
())
.
WithAdditionalAnnotations
(
Formatter
.
Annotation
);
}
var
@switch
=
convertToSwitchExpression
?
CreateSwitchExpressionStatement
(
target
,
sections
)
:
CreateSwitchStatement
(
ifStatement
,
target
,
sections
.
Select
(
section
=>
AsSwitchSectionSyntax
(
section
,
generator
)));
var
lastNode
=
sections
.
Last
().
SyntaxToRemove
;
@switch
=
@switch
.
WithLeadingTrivia
(
ifStatement
.
GetLeadingTrivia
())
.
WithTrailingTrivia
(
lastNode
.
GetTrailingTrivia
())
.
WithAdditionalAnnotations
(
Formatter
.
Annotation
)
.
WithAdditionalAnnotations
(
Simplifier
.
Annotation
);
var
nodesToRemove
=
sections
.
Skip
(
1
).
Select
(
s
=>
s
.
SyntaxToRemove
).
Where
(
s
=>
s
.
Parent
==
ifStatement
.
Parent
);
root
=
root
.
RemoveNodes
(
nodesToRemove
,
SyntaxRemoveOptions
.
KeepNoTrivia
);
root
=
root
.
ReplaceNode
(
root
.
FindNode
(
ifSpan
),
@switch
);
return
document
.
WithSyntaxRoot
(
root
);
}
SyntaxNode
AsSwitchSectionSyntax
(
AnalyzedSwitchSection
section
)
{
var
statements
=
AsSwitchSectionStatements
(
section
.
Body
);
return
section
.
Labels
.
IsDefault
?
generator
.
DefaultSwitchSection
(
statements
)
:
generator
.
SwitchSectionFromLabels
(
section
.
Labels
.
Select
(
AsSwitchLabelSyntax
),
statements
);
}
private
SyntaxNode
AsSwitchSectionSyntax
(
AnalyzedSwitchSection
section
,
SyntaxGenerator
generator
)
{
var
statements
=
AsSwitchSectionStatements
(
section
.
Body
);
return
section
.
Labels
.
IsDefault
?
generator
.
DefaultSwitchSection
(
statements
)
:
generator
.
SwitchSectionFromLabels
(
section
.
Labels
.
Select
(
AsSwitchLabelSyntax
),
statements
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录