Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
7ebfd2ce
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,发现更多精彩内容 >>
提交
7ebfd2ce
编写于
6月 28, 2019
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use switch expression
上级
f3d56ed9
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
54 addition
and
98 deletion
+54
-98
src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs
...p/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs
+9
-11
src/EditorFeatures/CSharp/AutomaticCompletion/CSharpBraceCompletionSessionProvider.cs
...tomaticCompletion/CSharpBraceCompletionSessionProvider.cs
+13
-16
src/EditorFeatures/TestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs
...s/TestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs
+7
-15
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
...or.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
+5
-8
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MiscellaneousFilesWorkspace.cs
...plementation/ProjectSystem/MiscellaneousFilesWorkspace.cs
+1
-10
src/VisualStudio/Core/Impl/CodeModel/FileCodeModel_Events.cs
src/VisualStudio/Core/Impl/CodeModel/FileCodeModel_Events.cs
+6
-12
src/VisualStudio/Core/SolutionExplorerShim/DiagnosticItem/BaseDiagnosticItem.BrowseObject.cs
...rerShim/DiagnosticItem/BaseDiagnosticItem.BrowseObject.cs
+7
-14
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
...s/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
+6
-12
未找到文件。
src/EditorFeatures/CSharp/AutomaticCompletion/AutomaticLineEnderCommandHandler.cs
浏览文件 @
7ebfd2ce
...
...
@@ -151,18 +151,16 @@ protected override string GetEndingString(Document document, int position, Cance
}
private
SyntaxNode
ParseNode
(
SyntaxTree
tree
,
SyntaxNode
owningNode
,
string
textToParse
)
{
switch
(
owningNode
)
=>
owningNode
switch
{
case
BaseFieldDeclarationSyntax
n
:
return
SyntaxFactory
.
ParseCompilationUnit
(
WrapInType
(
textToParse
),
options
:
(
CSharpParseOptions
)
tree
.
Options
);
case
BaseMethodDeclarationSyntax
n
:
return
SyntaxFactory
.
ParseCompilationUnit
(
WrapInType
(
textToParse
),
options
:
(
CSharpParseOptions
)
tree
.
Options
);
case
BasePropertyDeclarationSyntax
n
:
return
SyntaxFactory
.
ParseCompilationUnit
(
WrapInType
(
textToParse
),
options
:
(
CSharpParseOptions
)
tree
.
Options
);
case
StatementSyntax
n
:
return
SyntaxFactory
.
ParseStatement
(
textToParse
,
options
:
(
CSharpParseOptions
)
tree
.
Options
);
case
UsingDirectiveSyntax
n
:
return
SyntaxFactory
.
ParseCompilationUnit
(
textToParse
,
options
:
(
CSharpParseOptions
)
tree
.
Options
);
}
return
null
;
}
BaseFieldDeclarationSyntax
n
=>
SyntaxFactory
.
ParseCompilationUnit
(
WrapInType
(
textToParse
),
options
:
(
CSharpParseOptions
)
tree
.
Options
),
BaseMethodDeclarationSyntax
n
=>
SyntaxFactory
.
ParseCompilationUnit
(
WrapInType
(
textToParse
),
options
:
(
CSharpParseOptions
)
tree
.
Options
),
BasePropertyDeclarationSyntax
n
=>
SyntaxFactory
.
ParseCompilationUnit
(
WrapInType
(
textToParse
),
options
:
(
CSharpParseOptions
)
tree
.
Options
),
StatementSyntax
n
=>
SyntaxFactory
.
ParseStatement
(
textToParse
,
options
:
(
CSharpParseOptions
)
tree
.
Options
),
UsingDirectiveSyntax
n
=>
SyntaxFactory
.
ParseCompilationUnit
(
textToParse
,
options
:
(
CSharpParseOptions
)
tree
.
Options
),
_
=>
(
SyntaxNode
)
null
,
};
/// <summary>
/// wrap field in type
...
...
src/EditorFeatures/CSharp/AutomaticCompletion/CSharpBraceCompletionSessionProvider.cs
浏览文件 @
7ebfd2ce
...
...
@@ -68,25 +68,22 @@ protected override bool CheckCodeContext(Document document, int position, char o
protected
override
IEditorBraceCompletionSession
CreateEditorSession
(
Document
document
,
int
openingPosition
,
char
openingBrace
,
CancellationToken
cancellationToken
)
{
var
syntaxFactsService
=
document
.
GetLanguageService
<
ISyntaxFactsService
>();
switch
(
openingBrace
)
return
openingBrace
switch
{
case
BraceCompletionSessionProvider
.
CurlyBrace
.
OpenCharacter
:
return
InterpolationCompletionSession
.
IsContext
(
document
,
openingPosition
,
cancellationToken
)
?
new
InterpolationCompletionSession
()
:
(
IEditorBraceCompletionSession
)
new
CurlyBraceCompletionSession
(
syntaxFactsService
,
_smartIndentationService
,
_undoManager
);
BraceCompletionSessionProvider
.
CurlyBrace
.
OpenCharacter
=>
InterpolationCompletionSession
.
IsContext
(
document
,
openingPosition
,
cancellationToken
)
?
new
InterpolationCompletionSession
()
:
(
IEditorBraceCompletionSession
)
new
CurlyBraceCompletionSession
(
syntaxFactsService
,
_smartIndentationService
,
_undoManager
),
case
BraceCompletionSessionProvider
.
DoubleQuote
.
OpenCharacter
:
return
InterpolatedStringCompletionSession
.
IsContext
(
document
,
openingPosition
,
cancellationToken
)
?
new
InterpolatedStringCompletionSession
()
:
(
IEditorBraceCompletionSession
)
new
StringLiteralCompletionSession
(
syntaxFactsService
);
BraceCompletionSessionProvider
.
DoubleQuote
.
OpenCharacter
=>
InterpolatedStringCompletionSession
.
IsContext
(
document
,
openingPosition
,
cancellationToken
)
?
new
InterpolatedStringCompletionSession
()
:
(
IEditorBraceCompletionSession
)
new
StringLiteralCompletionSession
(
syntaxFactsService
),
case
BraceCompletionSessionProvider
.
Bracket
.
OpenCharacter
:
return
new
BracketCompletionSession
(
syntaxFactsService
);
case
BraceCompletionSessionProvider
.
Parenthesis
.
OpenCharacter
:
return
new
ParenthesisCompletionSession
(
syntaxFactsService
);
case
BraceCompletionSessionProvider
.
SingleQuote
.
OpenCharacter
:
return
new
CharLiteralCompletionSession
(
syntaxFactsService
);
case
BraceCompletionSessionProvider
.
LessAndGreaterThan
.
OpenCharacter
:
return
new
LessAndGreaterThanCompletionSession
(
syntaxFactsService
);
default
:
throw
ExceptionUtilities
.
UnexpectedValue
(
openingBrace
);
}
BraceCompletionSessionProvider
.
Bracket
.
OpenCharacter
=>
new
BracketCompletionSession
(
syntaxFactsService
),
BraceCompletionSessionProvider
.
Parenthesis
.
OpenCharacter
=>
new
ParenthesisCompletionSession
(
syntaxFactsService
),
BraceCompletionSessionProvider
.
SingleQuote
.
OpenCharacter
=>
new
CharLiteralCompletionSession
(
syntaxFactsService
),
BraceCompletionSessionProvider
.
LessAndGreaterThan
.
OpenCharacter
=>
new
LessAndGreaterThanCompletionSession
(
syntaxFactsService
),
_
=>
throw
ExceptionUtilities
.
UnexpectedValue
(
openingBrace
),
};
}
}
}
src/EditorFeatures/TestUtilities/Diagnostics/AbstractUserDiagnosticTest.cs
浏览文件 @
7ebfd2ce
...
...
@@ -129,22 +129,14 @@ protected Document GetDocumentAndAnnotatedSpan(TestWorkspace workspace, out stri
return
null
;
}
switch
(
annotation
)
return
annotation
switch
{
case
"FixAllInDocument"
:
return
FixAllScope
.
Document
;
case
"FixAllInProject"
:
return
FixAllScope
.
Project
;
case
"FixAllInSolution"
:
return
FixAllScope
.
Solution
;
case
"FixAllInSelection"
:
return
FixAllScope
.
Custom
;
}
throw
new
InvalidProgramException
(
"Incorrect FixAll annotation in test"
);
"FixAllInDocument"
=>
FixAllScope
.
Document
,
"FixAllInProject"
=>
FixAllScope
.
Project
,
"FixAllInSolution"
=>
FixAllScope
.
Solution
,
"FixAllInSelection"
=>
FixAllScope
.
Custom
,
_
=>
throw
new
InvalidProgramException
(
"Incorrect FixAll annotation in test"
),
};
}
internal
async
Task
<(
ImmutableArray
<
Diagnostic
>,
ImmutableArray
<
CodeAction
>,
CodeAction
actionToInvoke
)>
GetDiagnosticAndFixesAsync
(
...
...
src/Features/CSharp/Portable/ExtractMethod/CSharpMethodExtractor.CSharpCodeGenerator.MultipleStatementsCodeGenerator.cs
浏览文件 @
7ebfd2ce
...
...
@@ -101,15 +101,12 @@ private SyntaxList<StatementSyntax> GetStatementsFromContainer(SyntaxNode node)
Contract
.
ThrowIfNull
(
node
);
Contract
.
ThrowIfFalse
(
node
.
IsStatementContainerNode
());
switch
(
node
)
return
node
switch
{
case
BlockSyntax
blockNode
:
return
blockNode
.
Statements
;
case
SwitchSectionSyntax
switchSectionNode
:
return
switchSectionNode
.
Statements
;
}
return
Contract
.
FailWithReturn
<
SyntaxList
<
StatementSyntax
>>(
"unknown statements container!"
);
BlockSyntax
blockNode
=>
blockNode
.
Statements
,
SwitchSectionSyntax
switchSectionNode
=>
switchSectionNode
.
Statements
,
_
=>
Contract
.
FailWithReturn
<
SyntaxList
<
StatementSyntax
>>(
"unknown statements container!"
),
};
}
protected
override
SyntaxNode
GetFirstStatementOrInitializerSelectedAtCallSite
()
...
...
src/VisualStudio/Core/Def/Implementation/ProjectSystem/MiscellaneousFilesWorkspace.cs
浏览文件 @
7ebfd2ce
...
...
@@ -402,16 +402,7 @@ protected override void Dispose(bool finalize)
}
public
override
bool
CanApplyChange
(
ApplyChangesKind
feature
)
{
switch
(
feature
)
{
case
ApplyChangesKind
.
ChangeDocument
:
return
true
;
default
:
return
false
;
}
}
=>
feature
==
ApplyChangesKind
.
ChangeDocument
;
protected
override
void
ApplyDocumentTextChanged
(
DocumentId
documentId
,
SourceText
newText
)
{
...
...
src/VisualStudio/Core/Impl/CodeModel/FileCodeModel_Events.cs
浏览文件 @
7ebfd2ce
...
...
@@ -212,19 +212,13 @@ private object GetParentElementForCodeModelEvent(CodeModelEvent codeModelEvent)
}
private
EnvDTE
.
CodeElement
GetParameterElementForCodeModelEvent
(
CodeModelEvent
codeModelEvent
,
object
parentElement
)
{
switch
(
parentElement
)
=>
parentElement
switch
{
case
EnvDTE
.
CodeDelegate
parentDelegate
:
return
GetParameterElementForCodeModelEvent
(
codeModelEvent
,
parentDelegate
.
Parameters
,
parentElement
);
case
EnvDTE
.
CodeFunction
parentFunction
:
return
GetParameterElementForCodeModelEvent
(
codeModelEvent
,
parentFunction
.
Parameters
,
parentElement
);
case
EnvDTE80
.
CodeProperty2
parentProperty
:
return
GetParameterElementForCodeModelEvent
(
codeModelEvent
,
parentProperty
.
Parameters
,
parentElement
);
}
return
null
;
}
EnvDTE
.
CodeDelegate
parentDelegate
=>
GetParameterElementForCodeModelEvent
(
codeModelEvent
,
parentDelegate
.
Parameters
,
parentElement
),
EnvDTE
.
CodeFunction
parentFunction
=>
GetParameterElementForCodeModelEvent
(
codeModelEvent
,
parentFunction
.
Parameters
,
parentElement
),
EnvDTE80
.
CodeProperty2
parentProperty
=>
GetParameterElementForCodeModelEvent
(
codeModelEvent
,
parentProperty
.
Parameters
,
parentElement
),
_
=>
null
,
};
private
EnvDTE
.
CodeElement
GetParameterElementForCodeModelEvent
(
CodeModelEvent
codeModelEvent
,
EnvDTE
.
CodeElements
parentParameters
,
object
parentElement
)
{
...
...
src/VisualStudio/Core/SolutionExplorerShim/DiagnosticItem/BaseDiagnosticItem.BrowseObject.cs
浏览文件 @
7ebfd2ce
...
...
@@ -127,21 +127,14 @@ public BaseDiagnosticItem DiagnosticItem
}
private
string
MapDiagnosticSeverityToText
(
DiagnosticSeverity
severity
)
{
switch
(
severity
)
=>
severity
switch
{
case
DiagnosticSeverity
.
Hidden
:
return
SolutionExplorerShim
.
Hidden
;
case
DiagnosticSeverity
.
Info
:
return
SolutionExplorerShim
.
Info
;
case
DiagnosticSeverity
.
Warning
:
return
SolutionExplorerShim
.
Warning
;
case
DiagnosticSeverity
.
Error
:
return
SolutionExplorerShim
.
Error_
;
default
:
throw
ExceptionUtilities
.
UnexpectedValue
(
severity
);
}
}
DiagnosticSeverity
.
Hidden
=>
SolutionExplorerShim
.
Hidden
,
DiagnosticSeverity
.
Info
=>
SolutionExplorerShim
.
Info
,
DiagnosticSeverity
.
Warning
=>
SolutionExplorerShim
.
Warning
,
DiagnosticSeverity
.
Error
=>
SolutionExplorerShim
.
Error_
,
_
=>
throw
ExceptionUtilities
.
UnexpectedValue
(
severity
),
};
private
string
MapReportDiagnosticToText
(
ReportDiagnostic
report
)
{
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
浏览文件 @
7ebfd2ce
...
...
@@ -2765,19 +2765,13 @@ public override SyntaxNode InsertAccessors(SyntaxNode declaration, int index, IE
}
private
static
AccessorListSyntax
GetAccessorList
(
SyntaxNode
declaration
)
{
switch
(
declaration
.
Kind
())
=>
declaration
.
Kind
()
switch
{
case
SyntaxKind
.
PropertyDeclaration
:
return
((
PropertyDeclarationSyntax
)
declaration
).
AccessorList
;
case
SyntaxKind
.
IndexerDeclaration
:
return
((
IndexerDeclarationSyntax
)
declaration
).
AccessorList
;
case
SyntaxKind
.
EventDeclaration
:
return
((
EventDeclarationSyntax
)
declaration
).
AccessorList
;
default
:
return
null
;
}
}
SyntaxKind
.
PropertyDeclaration
=>
((
PropertyDeclarationSyntax
)
declaration
).
AccessorList
,
SyntaxKind
.
IndexerDeclaration
=>
((
IndexerDeclarationSyntax
)
declaration
).
AccessorList
,
SyntaxKind
.
EventDeclaration
=>
((
EventDeclarationSyntax
)
declaration
).
AccessorList
,
_
=>
null
,
};
private
static
bool
CanHaveAccessors
(
SyntaxNode
declaration
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录