Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
06c4312d
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,发现更多精彩内容 >>
未验证
提交
06c4312d
编写于
9月 28, 2020
作者:
M
msftbot[bot]
提交者:
GitHub
9月 28, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #48099 from CyrusNajmabadi/useSwitchExprs
Use switch expressions.
上级
cdb59565
2349c133
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
28 addition
and
76 deletion
+28
-76
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
...s/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
+28
-76
未找到文件。
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
浏览文件 @
06c4312d
...
...
@@ -1191,18 +1191,14 @@ private SyntaxNode InsertNamespaceImportsInternal(SyntaxNode declaration, int in
}
public
override
IReadOnlyList
<
SyntaxNode
>
GetMembers
(
SyntaxNode
declaration
)
{
return
Flatten
(
declaration
.
Kind
()
switch
=>
Flatten
(
declaration
switch
{
SyntaxKind
.
ClassDeclaration
=>
((
ClassDeclarationSyntax
)
declaration
).
Members
,
SyntaxKind
.
StructDeclaration
=>
((
StructDeclarationSyntax
)
declaration
).
Members
,
SyntaxKind
.
InterfaceDeclaration
=>
((
InterfaceDeclarationSyntax
)
declaration
).
Members
,
SyntaxKind
.
EnumDeclaration
=>
((
EnumDeclarationSyntax
)
declaration
).
Members
,
SyntaxKind
.
NamespaceDeclaration
=>
((
NamespaceDeclarationSyntax
)
declaration
).
Members
,
SyntaxKind
.
CompilationUnit
=>
((
CompilationUnitSyntax
)
declaration
).
Members
,
TypeDeclarationSyntax
type
=>
type
.
Members
,
EnumDeclarationSyntax
@enum
=>
@enum
.
Members
,
NamespaceDeclarationSyntax
@namespace
=>
@namespace
.
Members
,
CompilationUnitSyntax
compilationUnit
=>
compilationUnit
.
Members
,
_
=>
SpecializedCollections
.
EmptyReadOnlyList
<
SyntaxNode
>(),
});
}
private
static
ImmutableArray
<
SyntaxNode
>
Flatten
(
IEnumerable
<
SyntaxNode
>
declarations
)
{
...
...
@@ -1287,29 +1283,14 @@ public override SyntaxNode InsertMembers(SyntaxNode declaration, int index, IEnu
}
else
{
switch
(
declaration
.
Kind
())
return
declaration
switch
{
case
SyntaxKind
.
ClassDeclaration
:
var
cd
=
(
ClassDeclarationSyntax
)
declaration
;
return
cd
.
WithMembers
(
cd
.
Members
.
AddRange
(
newMembers
));
case
SyntaxKind
.
StructDeclaration
:
var
sd
=
(
StructDeclarationSyntax
)
declaration
;
return
sd
.
WithMembers
(
sd
.
Members
.
AddRange
(
newMembers
));
case
SyntaxKind
.
InterfaceDeclaration
:
var
id
=
(
InterfaceDeclarationSyntax
)
declaration
;
return
id
.
WithMembers
(
id
.
Members
.
AddRange
(
newMembers
));
case
SyntaxKind
.
EnumDeclaration
:
var
ed
=
(
EnumDeclarationSyntax
)
declaration
;
return
ed
.
WithMembers
(
ed
.
Members
.
AddRange
(
newMembers
.
OfType
<
EnumMemberDeclarationSyntax
>()));
case
SyntaxKind
.
NamespaceDeclaration
:
var
nd
=
(
NamespaceDeclarationSyntax
)
declaration
;
return
nd
.
WithMembers
(
nd
.
Members
.
AddRange
(
newMembers
));
case
SyntaxKind
.
CompilationUnit
:
var
cu
=
(
CompilationUnitSyntax
)
declaration
;
return
cu
.
WithMembers
(
cu
.
Members
.
AddRange
(
newMembers
));
default
:
return
declaration
;
}
TypeDeclarationSyntax
type
=>
type
.
WithMembers
(
type
.
Members
.
AddRange
(
newMembers
)),
EnumDeclarationSyntax
@enum
=>
@enum
.
WithMembers
(
@enum
.
Members
.
AddRange
(
newMembers
.
OfType
<
EnumMemberDeclarationSyntax
>())),
NamespaceDeclarationSyntax
@namespace
=>
@namespace
.
WithMembers
(
@namespace
.
Members
.
AddRange
(
newMembers
)),
CompilationUnitSyntax
compilationUnit
=>
compilationUnit
.
WithMembers
(
compilationUnit
.
Members
.
AddRange
(
newMembers
)),
_
=>
declaration
,
};
}
}
...
...
@@ -1658,13 +1639,11 @@ public override SyntaxNode WithTypeParameters(SyntaxNode declaration, IEnumerabl
{
var
typeParameters
=
AsTypeParameterList
(
typeParameterNames
);
return
declaration
.
Kind
()
switch
return
declaration
switch
{
SyntaxKind
.
MethodDeclaration
=>
((
MethodDeclarationSyntax
)
declaration
).
WithTypeParameterList
(
typeParameters
),
SyntaxKind
.
ClassDeclaration
=>
((
ClassDeclarationSyntax
)
declaration
).
WithTypeParameterList
(
typeParameters
),
SyntaxKind
.
StructDeclaration
=>
((
StructDeclarationSyntax
)
declaration
).
WithTypeParameterList
(
typeParameters
),
SyntaxKind
.
InterfaceDeclaration
=>
((
InterfaceDeclarationSyntax
)
declaration
).
WithTypeParameterList
(
typeParameters
),
SyntaxKind
.
DelegateDeclaration
=>
((
DelegateDeclarationSyntax
)
declaration
).
WithTypeParameterList
(
typeParameters
),
MethodDeclarationSyntax
method
=>
method
.
WithTypeParameterList
(
typeParameters
),
TypeDeclarationSyntax
type
=>
type
.
WithTypeParameterList
(
typeParameters
),
DelegateDeclarationSyntax
@delegate
=>
@delegate
.
WithTypeParameterList
(
typeParameters
),
_
=>
declaration
,
};
}
...
...
@@ -1682,32 +1661,13 @@ private static ExplicitInterfaceSpecifierSyntax CreateExplicitInterfaceSpecifier
=>
SyntaxFactory
.
ExplicitInterfaceSpecifier
(
explicitInterfaceImplementations
[
0
].
ContainingType
.
GenerateNameSyntax
());
public
override
SyntaxNode
WithTypeConstraint
(
SyntaxNode
declaration
,
string
typeParameterName
,
SpecialTypeConstraintKind
kinds
,
IEnumerable
<
SyntaxNode
>
types
)
{
switch
(
declaration
.
Kind
())
=>
declaration
switch
{
case
SyntaxKind
.
MethodDeclaration
:
var
method
=
(
MethodDeclarationSyntax
)
declaration
;
return
method
.
WithConstraintClauses
(
WithTypeConstraints
(
method
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
));
case
SyntaxKind
.
ClassDeclaration
:
var
cls
=
(
ClassDeclarationSyntax
)
declaration
;
return
cls
.
WithConstraintClauses
(
WithTypeConstraints
(
cls
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
));
case
SyntaxKind
.
StructDeclaration
:
var
str
=
(
StructDeclarationSyntax
)
declaration
;
return
str
.
WithConstraintClauses
(
WithTypeConstraints
(
str
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
));
case
SyntaxKind
.
InterfaceDeclaration
:
var
iface
=
(
InterfaceDeclarationSyntax
)
declaration
;
return
iface
.
WithConstraintClauses
(
WithTypeConstraints
(
iface
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
));
case
SyntaxKind
.
DelegateDeclaration
:
var
del
=
(
DelegateDeclarationSyntax
)
declaration
;
return
del
.
WithConstraintClauses
(
WithTypeConstraints
(
del
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
));
default
:
return
declaration
;
}
}
MethodDeclarationSyntax
method
=>
method
.
WithConstraintClauses
(
WithTypeConstraints
(
method
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
)),
TypeDeclarationSyntax
type
=>
type
.
WithConstraintClauses
(
WithTypeConstraints
(
type
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
)),
DelegateDeclarationSyntax
@delegate
=>
@delegate
.
WithConstraintClauses
(
WithTypeConstraints
(
@delegate
.
ConstraintClauses
,
typeParameterName
,
kinds
,
types
)),
_
=>
declaration
,
};
private
static
SyntaxList
<
TypeParameterConstraintClauseSyntax
>
WithTypeConstraints
(
SyntaxList
<
TypeParameterConstraintClauseSyntax
>
clauses
,
string
typeParameterName
,
SpecialTypeConstraintKind
kinds
,
IEnumerable
<
SyntaxNode
>
types
)
...
...
@@ -2648,22 +2608,14 @@ private static SyntaxNode AddBaseList(SyntaxNode declaration, BaseListSyntax bas
}
private
static
BaseListSyntax
GetBaseList
(
SyntaxNode
declaration
)
=>
declaration
.
Kind
()
switch
{
SyntaxKind
.
ClassDeclaration
=>
((
ClassDeclarationSyntax
)
declaration
).
BaseList
,
SyntaxKind
.
StructDeclaration
=>
((
StructDeclarationSyntax
)
declaration
).
BaseList
,
SyntaxKind
.
InterfaceDeclaration
=>
((
InterfaceDeclarationSyntax
)
declaration
).
BaseList
,
_
=>
null
,
};
=>
declaration
is
TypeDeclarationSyntax
typeDeclaration
?
typeDeclaration
.
BaseList
:
null
;
private
static
SyntaxNode
WithBaseList
(
SyntaxNode
declaration
,
BaseListSyntax
baseList
)
=>
declaration
.
Kind
()
switch
{
SyntaxKind
.
ClassDeclaration
=>
((
ClassDeclarationSyntax
)
declaration
).
WithBaseList
(
baseList
),
SyntaxKind
.
StructDeclaration
=>
((
StructDeclarationSyntax
)
declaration
).
WithBaseList
(
baseList
),
SyntaxKind
.
InterfaceDeclaration
=>
((
InterfaceDeclarationSyntax
)
declaration
).
WithBaseList
(
baseList
),
_
=>
declaration
,
};
=>
declaration
is
TypeDeclarationSyntax
typeDeclaration
?
typeDeclaration
.
WithBaseList
(
baseList
)
:
declaration
;
#
endregion
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录