Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
1a01208c
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,发现更多精彩内容 >>
提交
1a01208c
编写于
7月 18, 2019
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use switch expressions
上级
8c03c91f
变更
15
展开全部
隐藏空白更改
内联
并排
Showing
15 changed file
with
247 addition
and
340 deletion
+247
-340
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs
...ble/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs
+6
-10
src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_2.cs
...es/Core/Portable/Shared/Extensions/ISymbolExtensions_2.cs
+7
-9
src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_Sorting.cs
...e/Portable/Shared/Extensions/ISymbolExtensions_Sorting.cs
+6
-8
src/Workspaces/CSharp/Portable/AddImports/CSharpAddImportsService.cs
...ces/CSharp/Portable/AddImports/CSharpAddImportsService.cs
+10
-14
src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs
...s/CSharp/Portable/Classification/ClassificationHelpers.cs
+14
-24
src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/OperatorOverloadSyntaxClassifier.cs
.../SyntaxClassification/OperatorOverloadSyntaxClassifier.cs
+7
-14
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationHelpers.cs
...rp/Portable/CodeGeneration/CSharpCodeGenerationHelpers.cs
+9
-16
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
...rp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
+16
-37
src/Workspaces/CSharp/Portable/CodeGeneration/ExpressionGenerator.cs
...ces/CSharp/Portable/CodeGeneration/ExpressionGenerator.cs
+20
-24
src/Workspaces/CSharp/Portable/CodeGeneration/NamespaceGenerator.cs
...aces/CSharp/Portable/CodeGeneration/NamespaceGenerator.cs
+5
-12
src/Workspaces/CSharp/Portable/CodeStyle/CSharpCodeStyleOptions_Parsing.cs
...harp/Portable/CodeStyle/CSharpCodeStyleOptions_Parsing.cs
+22
-34
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
...nguageServices/CSharpTypeInferenceService.TypeInferrer.cs
+106
-108
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.State.cs
.../CSharp/Portable/Utilities/CSharpTypeStyleHelper.State.cs
+6
-12
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.cs
...spaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.cs
+12
-16
src/Workspaces/Core/Portable/Workspace/Solution/MetadataOnlyImage.cs
...ces/Core/Portable/Workspace/Solution/MetadataOnlyImage.cs
+1
-2
未找到文件。
src/Features/Core/Portable/Diagnostics/EngineV2/DiagnosticIncrementalAnalyzer.cs
浏览文件 @
1a01208c
...
...
@@ -235,17 +235,13 @@ private static ImmutableArray<DiagnosticData> GetResult(DiagnosticAnalysisResult
return
ImmutableArray
<
DiagnosticData
>.
Empty
;
}
switch
(
kind
)
return
kind
switch
{
case
AnalysisKind
.
Syntax
:
return
result
.
GetResultOrEmpty
(
result
.
SyntaxLocals
,
id
);
case
AnalysisKind
.
Semantic
:
return
result
.
GetResultOrEmpty
(
result
.
SemanticLocals
,
id
);
case
AnalysisKind
.
NonLocal
:
return
result
.
GetResultOrEmpty
(
result
.
NonLocals
,
id
);
default
:
return
Contract
.
FailWithReturn
<
ImmutableArray
<
DiagnosticData
>>(
"shouldn't reach here"
);
}
AnalysisKind
.
Syntax
=>
result
.
GetResultOrEmpty
(
result
.
SyntaxLocals
,
id
),
AnalysisKind
.
Semantic
=>
result
.
GetResultOrEmpty
(
result
.
SemanticLocals
,
id
),
AnalysisKind
.
NonLocal
=>
result
.
GetResultOrEmpty
(
result
.
NonLocals
,
id
),
_
=>
Contract
.
FailWithReturn
<
ImmutableArray
<
DiagnosticData
>>(
"shouldn't reach here"
),
};
}
public
void
LogAnalyzerCountSummary
()
...
...
src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_2.cs
浏览文件 @
1a01208c
...
...
@@ -182,16 +182,14 @@ public static IEnumerable<TaggedText> GetDocumentationParts(this ISymbol symbol,
}
private
static
string
GetDocumentation
(
ISymbol
symbol
,
CancellationToken
cancellationToken
)
{
switch
(
symbol
)
=>
symbol
switch
{
case
IParameterSymbol
parameter
:
return
GetParameterDocumentation
(
parameter
,
cancellationToken
);
case
ITypeParameterSymbol
typeParam
:
return
typeParam
.
ContainingSymbol
.
GetDocumentationComment
(
cancellationToken
:
cancellationToken
).
GetTypeParameterText
(
symbol
.
Name
);
case
IMethodSymbol
method
:
return
GetMethodDocumentation
(
method
);
case
IAliasSymbol
alias
:
return
alias
.
Target
.
GetDocumentationComment
(
cancellationToken
:
cancellationToken
).
SummaryText
;
default
:
return
symbol
.
GetDocumentationComment
(
cancellationToken
:
cancellationToken
).
SummaryText
;
}
}
IParameterSymbol
parameter
=>
GetParameterDocumentation
(
parameter
,
cancellationToken
),
ITypeParameterSymbol
typeParam
=>
typeParam
.
ContainingSymbol
.
GetDocumentationComment
(
cancellationToken
:
cancellationToken
).
GetTypeParameterText
(
symbol
.
Name
),
IMethodSymbol
method
=>
GetMethodDocumentation
(
method
),
IAliasSymbol
alias
=>
alias
.
Target
.
GetDocumentationComment
(
cancellationToken
:
cancellationToken
).
SummaryText
,
_
=>
symbol
.
GetDocumentationComment
(
cancellationToken
:
cancellationToken
).
SummaryText
,
};
private
static
string
GetParameterDocumentation
(
IParameterSymbol
parameter
,
CancellationToken
cancellationToken
)
{
...
...
src/Features/Core/Portable/Shared/Extensions/ISymbolExtensions_Sorting.cs
浏览文件 @
1a01208c
...
...
@@ -27,15 +27,13 @@ internal partial class ISymbolExtensions2
}
private
static
INamedTypeSymbol
GetNamedType
(
ITypeSymbol
type
)
{
switch
(
type
)
=>
type
switch
{
case
INamedTypeSymbol
namedType
:
return
namedType
;
case
IArrayTypeSymbol
arrayType
:
return
GetNamedType
(
arrayType
.
ElementType
);
case
IPointerTypeSymbol
pointerType
:
return
GetNamedType
(
pointerType
.
PointedAtType
);
default
:
return
null
;
}
}
INamedTypeSymbol
namedType
=>
namedType
,
IArrayTypeSymbol
arrayType
=>
GetNamedType
(
arrayType
.
ElementType
),
IPointerTypeSymbol
pointerType
=>
GetNamedType
(
pointerType
.
PointedAtType
),
_
=>
null
,
};
private
static
int
CompareParameters
(
ImmutableArray
<
IParameterSymbol
>
xParameters
,
string
[]
xTypeNames
,
...
...
src/Workspaces/CSharp/Portable/AddImports/CSharpAddImportsService.cs
浏览文件 @
1a01208c
...
...
@@ -50,24 +50,20 @@ protected override bool IsStaticUsing(UsingDirectiveSyntax usingOrAlias)
}
protected
override
SyntaxList
<
UsingDirectiveSyntax
>
GetUsingsAndAliases
(
SyntaxNode
node
)
{
switch
(
node
)
=>
node
switch
{
case
CompilationUnitSyntax
c
:
return
c
.
Usings
;
case
NamespaceDeclarationSyntax
n
:
return
n
.
Usings
;
default
:
return
default
;
}
}
CompilationUnitSyntax
c
=>
c
.
Usings
,
NamespaceDeclarationSyntax
n
=>
n
.
Usings
,
_
=>
default
,
};
protected
override
SyntaxList
<
ExternAliasDirectiveSyntax
>
GetExterns
(
SyntaxNode
node
)
{
switch
(
node
)
=>
node
switch
{
case
CompilationUnitSyntax
c
:
return
c
.
Externs
;
case
NamespaceDeclarationSyntax
n
:
return
n
.
Externs
;
default
:
return
default
;
}
}
CompilationUnitSyntax
c
=>
c
.
Externs
,
NamespaceDeclarationSyntax
n
=>
n
.
Externs
,
_
=>
default
,
};
private
class
Rewriter
:
CSharpSyntaxRewriter
{
...
...
src/Workspaces/CSharp/Portable/Classification/ClassificationHelpers.cs
浏览文件 @
1a01208c
...
...
@@ -232,16 +232,13 @@ private static string GetClassificationForIdentifier(SyntaxToken token)
else
if
(
token
.
Parent
is
VariableDeclaratorSyntax
variableDeclarator
&&
variableDeclarator
.
Identifier
==
token
)
{
var
varDecl
=
variableDeclarator
.
Parent
as
VariableDeclarationSyntax
;
switch
(
varDecl
.
Parent
)
return
varDecl
.
Parent
switch
{
case
FieldDeclarationSyntax
fieldDeclaration
:
return
fieldDeclaration
.
Modifiers
.
Any
(
SyntaxKind
.
ConstKeyword
)
?
ClassificationTypeNames
.
ConstantName
:
ClassificationTypeNames
.
FieldName
;
case
LocalDeclarationStatementSyntax
localDeclarationStatement
:
return
localDeclarationStatement
.
IsConst
?
ClassificationTypeNames
.
ConstantName
:
ClassificationTypeNames
.
LocalName
;
case
EventFieldDeclarationSyntax
aventFieldDeclarationSyntax
:
return
ClassificationTypeNames
.
EventName
;
}
return
ClassificationTypeNames
.
LocalName
;
FieldDeclarationSyntax
fieldDeclaration
=>
fieldDeclaration
.
Modifiers
.
Any
(
SyntaxKind
.
ConstKeyword
)
?
ClassificationTypeNames
.
ConstantName
:
ClassificationTypeNames
.
FieldName
,
LocalDeclarationStatementSyntax
localDeclarationStatement
=>
localDeclarationStatement
.
IsConst
?
ClassificationTypeNames
.
ConstantName
:
ClassificationTypeNames
.
LocalName
,
EventFieldDeclarationSyntax
aventFieldDeclarationSyntax
=>
ClassificationTypeNames
.
EventName
,
_
=>
ClassificationTypeNames
.
LocalName
,
};
}
else
if
(
token
.
Parent
is
SingleVariableDesignationSyntax
singleVariableDesignation
&&
singleVariableDesignation
.
Identifier
==
token
)
{
...
...
@@ -347,21 +344,14 @@ private static bool IsExtensionMethod(MethodDeclarationSyntax methodDeclaration)
}
private
static
string
GetClassificationForTypeDeclarationIdentifier
(
SyntaxToken
identifier
)
{
switch
(
identifier
.
Parent
.
Kind
())
{
case
SyntaxKind
.
ClassDeclaration
:
return
ClassificationTypeNames
.
ClassName
;
case
SyntaxKind
.
EnumDeclaration
:
return
ClassificationTypeNames
.
EnumName
;
case
SyntaxKind
.
StructDeclaration
:
return
ClassificationTypeNames
.
StructName
;
case
SyntaxKind
.
InterfaceDeclaration
:
return
ClassificationTypeNames
.
InterfaceName
;
default
:
return
null
;
}
}
=>
identifier
.
Parent
.
Kind
()
switch
{
SyntaxKind
.
ClassDeclaration
=>
ClassificationTypeNames
.
ClassName
,
SyntaxKind
.
EnumDeclaration
=>
ClassificationTypeNames
.
EnumName
,
SyntaxKind
.
StructDeclaration
=>
ClassificationTypeNames
.
StructName
,
SyntaxKind
.
InterfaceDeclaration
=>
ClassificationTypeNames
.
InterfaceName
,
_
=>
null
,
};
private
static
string
GetClassificationForPunctuation
(
SyntaxToken
token
)
{
...
...
src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/OperatorOverloadSyntaxClassifier.cs
浏览文件 @
1a01208c
...
...
@@ -39,20 +39,13 @@ internal class OperatorOverloadSyntaxClassifier : AbstractSyntaxClassifier
}
private
static
TextSpan
GetOperatorTokenSpan
(
SyntaxNode
syntax
)
{
switch
(
syntax
)
=>
syntax
switch
{
case
AssignmentExpressionSyntax
assignmentExpression
:
return
assignmentExpression
.
OperatorToken
.
Span
;
case
BinaryExpressionSyntax
binaryExpression
:
return
binaryExpression
.
OperatorToken
.
Span
;
case
PrefixUnaryExpressionSyntax
prefixUnaryExpression
:
return
prefixUnaryExpression
.
OperatorToken
.
Span
;
case
PostfixUnaryExpressionSyntax
postfixUnaryExpression
:
return
postfixUnaryExpression
.
OperatorToken
.
Span
;
}
return
default
;
}
AssignmentExpressionSyntax
assignmentExpression
=>
assignmentExpression
.
OperatorToken
.
Span
,
BinaryExpressionSyntax
binaryExpression
=>
binaryExpression
.
OperatorToken
.
Span
,
PrefixUnaryExpressionSyntax
prefixUnaryExpression
=>
prefixUnaryExpression
.
OperatorToken
.
Span
,
PostfixUnaryExpressionSyntax
postfixUnaryExpression
=>
postfixUnaryExpression
.
OperatorToken
.
Span
,
_
=>
default
,
};
}
}
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationHelpers.cs
浏览文件 @
1a01208c
...
...
@@ -234,23 +234,16 @@ public static CodeGenerationDestination GetDestination(SyntaxNode destination)
{
if
(
destination
!=
null
)
{
switch
(
destination
.
Kind
())
return
destination
.
Kind
()
switch
{
case
SyntaxKind
.
ClassDeclaration
:
return
CodeGenerationDestination
.
ClassType
;
case
SyntaxKind
.
CompilationUnit
:
return
CodeGenerationDestination
.
CompilationUnit
;
case
SyntaxKind
.
EnumDeclaration
:
return
CodeGenerationDestination
.
EnumType
;
case
SyntaxKind
.
InterfaceDeclaration
:
return
CodeGenerationDestination
.
InterfaceType
;
case
SyntaxKind
.
NamespaceDeclaration
:
return
CodeGenerationDestination
.
Namespace
;
case
SyntaxKind
.
StructDeclaration
:
return
CodeGenerationDestination
.
StructType
;
default
:
return
CodeGenerationDestination
.
Unspecified
;
}
SyntaxKind
.
ClassDeclaration
=>
CodeGenerationDestination
.
ClassType
,
SyntaxKind
.
CompilationUnit
=>
CodeGenerationDestination
.
CompilationUnit
,
SyntaxKind
.
EnumDeclaration
=>
CodeGenerationDestination
.
EnumType
,
SyntaxKind
.
InterfaceDeclaration
=>
CodeGenerationDestination
.
InterfaceType
,
SyntaxKind
.
NamespaceDeclaration
=>
CodeGenerationDestination
.
Namespace
,
SyntaxKind
.
StructDeclaration
=>
CodeGenerationDestination
.
StructType
,
_
=>
CodeGenerationDestination
.
Unspecified
,
};
}
return
CodeGenerationDestination
.
Unspecified
;
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
浏览文件 @
1a01208c
...
...
@@ -327,25 +327,15 @@ protected override TDeclarationNode AddNamespace<TDeclarationNode>(TDeclarationN
var
attributeSyntaxList
=
AttributeGenerator
.
GenerateAttributeLists
(
attributes
.
ToImmutableArray
(),
options
,
target
).
ToArray
();
switch
(
destination
)
return
destination
switch
{
case
MemberDeclarationSyntax
member
:
// Handle all members including types.
return
Cast
<
TDeclarationNode
>(
member
.
AddAttributeLists
(
attributeSyntaxList
));
case
AccessorDeclarationSyntax
accessor
:
// Handle accessors
return
Cast
<
TDeclarationNode
>(
accessor
.
AddAttributeLists
(
attributeSyntaxList
));
case
CompilationUnitSyntax
compilationUnit
:
// Handle global attributes
return
Cast
<
TDeclarationNode
>(
compilationUnit
.
AddAttributeLists
(
attributeSyntaxList
));
case
ParameterSyntax
parameter
:
// Handle parameters
return
Cast
<
TDeclarationNode
>(
parameter
.
AddAttributeLists
(
attributeSyntaxList
));
case
TypeParameterSyntax
typeParameter
:
return
Cast
<
TDeclarationNode
>(
typeParameter
.
AddAttributeLists
(
attributeSyntaxList
));
}
return
destination
;
MemberDeclarationSyntax
member
=>
Cast
<
TDeclarationNode
>(
member
.
AddAttributeLists
(
attributeSyntaxList
)),
AccessorDeclarationSyntax
accessor
=>
Cast
<
TDeclarationNode
>(
accessor
.
AddAttributeLists
(
attributeSyntaxList
)),
CompilationUnitSyntax
compilationUnit
=>
Cast
<
TDeclarationNode
>(
compilationUnit
.
AddAttributeLists
(
attributeSyntaxList
)),
ParameterSyntax
parameter
=>
Cast
<
TDeclarationNode
>(
parameter
.
AddAttributeLists
(
attributeSyntaxList
)),
TypeParameterSyntax
typeParameter
=>
Cast
<
TDeclarationNode
>(
typeParameter
.
AddAttributeLists
(
attributeSyntaxList
)),
_
=>
destination
,
};
}
protected
override
TDeclarationNode
AddMembers
<
TDeclarationNode
>(
TDeclarationNode
destination
,
IEnumerable
<
SyntaxNode
>
members
)
...
...
@@ -637,25 +627,14 @@ public override SyntaxNode CreateFieldDeclaration(IFieldSymbol field, CodeGenera
}
private
static
TDeclarationNode
UpdateDeclarationModifiers
<
TDeclarationNode
>(
TDeclarationNode
declaration
,
Func
<
SyntaxTokenList
,
SyntaxTokenList
>
computeNewModifiersList
,
CodeGenerationOptions
options
)
{
switch
(
declaration
)
{
case
BaseTypeDeclarationSyntax
typeDeclaration
:
// Handle type declarations.
return
Cast
<
TDeclarationNode
>(
typeDeclaration
.
WithModifiers
(
computeNewModifiersList
(
typeDeclaration
.
Modifiers
)));
case
BaseFieldDeclarationSyntax
fieldDeclaration
:
// Handle field declarations.
return
Cast
<
TDeclarationNode
>(
fieldDeclaration
.
WithModifiers
(
computeNewModifiersList
(
fieldDeclaration
.
Modifiers
)));
case
BaseMethodDeclarationSyntax
methodDeclaration
:
// Handle method declarations.
return
Cast
<
TDeclarationNode
>(
methodDeclaration
.
WithModifiers
(
computeNewModifiersList
(
methodDeclaration
.
Modifiers
)));
case
BasePropertyDeclarationSyntax
propertyDeclaration
:
// Handle properties.
return
Cast
<
TDeclarationNode
>(
propertyDeclaration
.
WithModifiers
(
computeNewModifiersList
(
propertyDeclaration
.
Modifiers
)));
}
return
declaration
;
}
=>
declaration
switch
{
BaseTypeDeclarationSyntax
typeDeclaration
=>
Cast
<
TDeclarationNode
>(
typeDeclaration
.
WithModifiers
(
computeNewModifiersList
(
typeDeclaration
.
Modifiers
))),
BaseFieldDeclarationSyntax
fieldDeclaration
=>
Cast
<
TDeclarationNode
>(
fieldDeclaration
.
WithModifiers
(
computeNewModifiersList
(
fieldDeclaration
.
Modifiers
))),
BaseMethodDeclarationSyntax
methodDeclaration
=>
Cast
<
TDeclarationNode
>(
methodDeclaration
.
WithModifiers
(
computeNewModifiersList
(
methodDeclaration
.
Modifiers
))),
BasePropertyDeclarationSyntax
propertyDeclaration
=>
Cast
<
TDeclarationNode
>(
propertyDeclaration
.
WithModifiers
(
computeNewModifiersList
(
propertyDeclaration
.
Modifiers
))),
_
=>
declaration
,
};
public
override
TDeclarationNode
UpdateDeclarationModifiers
<
TDeclarationNode
>(
TDeclarationNode
declaration
,
IEnumerable
<
SyntaxToken
>
newModifiers
,
CodeGenerationOptions
options
,
CancellationToken
cancellationToken
)
{
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/ExpressionGenerator.cs
浏览文件 @
1a01208c
...
...
@@ -71,31 +71,27 @@ private static ExpressionSyntax GenerateNullLiteral()
return
GenerateNonEnumValueExpression
(
type
,
value
,
canUseFieldReference
);
}
internal
static
ExpressionSyntax
GenerateNonEnumValueExpression
(
ITypeSymbol
type
,
object
value
,
bool
canUseFieldReference
)
{
switch
(
value
)
internal
static
ExpressionSyntax
GenerateNonEnumValueExpression
(
ITypeSymbol
type
,
object
value
,
bool
canUseFieldReference
)
=>
value
switch
{
case
bool
val
:
return
GenerateBooleanLiteralExpression
(
val
);
case
string
val
:
return
GenerateStringLiteralExpression
(
val
);
case
char
val
:
return
GenerateCharLiteralExpression
(
val
);
case
sbyte
val
:
return
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
SByteSpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
v
),
x
=>
x
<
0
,
x
=>
(
sbyte
)-
x
,
"128"
);
case
short
val
:
return
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
Int16SpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
v
),
x
=>
x
<
0
,
x
=>
(
short
)-
x
,
"32768"
);
case
int
val
:
return
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
Int32SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
,
x
=>
x
<
0
,
x
=>
-
x
,
"2147483648"
);
case
long
val
:
return
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
Int64SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
,
x
=>
x
<
0
,
x
=>
-
x
,
"9223372036854775808"
);
case
byte
val
:
return
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
ByteSpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
v
));
case
ushort
val
:
return
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
UInt16SpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
(
uint
)
v
));
case
uint
val
:
return
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
UInt32SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
);
case
ulong
val
:
return
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
UInt64SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
);
case
float
val
:
return
GenerateSingleLiteralExpression
(
type
,
val
,
canUseFieldReference
);
case
double
val
:
return
GenerateDoubleLiteralExpression
(
type
,
val
,
canUseFieldReference
);
case
decimal
val
:
return
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
DecimalSpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
,
x
=>
x
<
0
,
x
=>
-
x
,
null
);
}
return
type
==
null
||
type
.
IsReferenceType
||
type
.
IsPointerType
()
||
type
.
IsNullable
()
?
GenerateNullLiteral
()
:
(
ExpressionSyntax
)
CSharpSyntaxGenerator
.
Instance
.
DefaultExpression
(
type
);
}
bool
val
=>
GenerateBooleanLiteralExpression
(
val
),
string
val
=>
GenerateStringLiteralExpression
(
val
),
char
val
=>
GenerateCharLiteralExpression
(
val
),
sbyte
val
=>
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
SByteSpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
v
),
x
=>
x
<
0
,
x
=>
(
sbyte
)-
x
,
"128"
),
short
val
=>
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
Int16SpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
v
),
x
=>
x
<
0
,
x
=>
(
short
)-
x
,
"32768"
),
int
val
=>
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
Int32SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
,
x
=>
x
<
0
,
x
=>
-
x
,
"2147483648"
),
long
val
=>
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
Int64SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
,
x
=>
x
<
0
,
x
=>
-
x
,
"9223372036854775808"
),
byte
val
=>
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
ByteSpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
v
)),
ushort
val
=>
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
UInt16SpecialValues
,
null
,
canUseFieldReference
,
(
s
,
v
)
=>
SyntaxFactory
.
Literal
(
s
,
(
uint
)
v
)),
uint
val
=>
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
UInt32SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
),
ulong
val
=>
GenerateNonNegativeLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
UInt64SpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
),
float
val
=>
GenerateSingleLiteralExpression
(
type
,
val
,
canUseFieldReference
),
double
val
=>
GenerateDoubleLiteralExpression
(
type
,
val
,
canUseFieldReference
),
decimal
val
=>
GenerateLiteralExpression
(
type
,
val
,
LiteralSpecialValues
.
DecimalSpecialValues
,
null
,
canUseFieldReference
,
SyntaxFactory
.
Literal
,
x
=>
x
<
0
,
x
=>
-
x
,
null
),
_
=>
type
==
null
||
type
.
IsReferenceType
||
type
.
IsPointerType
()
||
type
.
IsNullable
()
?
GenerateNullLiteral
()
:
(
ExpressionSyntax
)
CSharpSyntaxGenerator
.
Instance
.
DefaultExpression
(
type
),
};
private
static
ExpressionSyntax
GenerateBooleanLiteralExpression
(
bool
val
)
{
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/NamespaceGenerator.cs
浏览文件 @
1a01208c
...
...
@@ -112,19 +112,12 @@ internal static class NamespaceGenerator
}
private
static
SyntaxNode
RemoveAllMembers
(
SyntaxNode
declaration
)
{
switch
(
declaration
.
Kind
())
=>
declaration
.
Kind
()
switch
{
case
SyntaxKind
.
CompilationUnit
:
return
((
CompilationUnitSyntax
)
declaration
).
WithMembers
(
default
);
case
SyntaxKind
.
NamespaceDeclaration
:
return
((
NamespaceDeclarationSyntax
)
declaration
).
WithMembers
(
default
);
default
:
return
declaration
;
}
}
SyntaxKind
.
CompilationUnit
=>
((
CompilationUnitSyntax
)
declaration
).
WithMembers
(
default
),
SyntaxKind
.
NamespaceDeclaration
=>
((
NamespaceDeclarationSyntax
)
declaration
).
WithMembers
(
default
),
_
=>
declaration
,
};
private
static
SyntaxList
<
UsingDirectiveSyntax
>
GenerateUsingDirectives
(
INamespaceSymbol
innermostNamespace
)
{
...
...
src/Workspaces/CSharp/Portable/CodeStyle/CSharpCodeStyleOptions_Parsing.cs
浏览文件 @
1a01208c
...
...
@@ -42,14 +42,13 @@ private static string GetExpressionBodyPreferenceEditorConfigString(CodeStyleOpt
Debug
.
Assert
(
value
.
Notification
!=
null
);
var
notificationString
=
value
.
Notification
.
ToEditorConfigString
();
switch
(
value
.
Value
)
return
value
.
Value
switch
{
case
ExpressionBodyPreference
.
Never
:
return
$"false:
{
notificationString
}
"
;
case
ExpressionBodyPreference
.
WhenPossible
:
return
$"true:
{
notificationString
}
"
;
case
ExpressionBodyPreference
.
WhenOnSingleLine
:
return
$"when_on_single_line:
{
notificationString
}
"
;
default
:
throw
new
NotSupportedException
();
}
ExpressionBodyPreference
.
Never
=>
$"false:
{
notificationString
}
"
,
ExpressionBodyPreference
.
WhenPossible
=>
$"true:
{
notificationString
}
"
,
ExpressionBodyPreference
.
WhenOnSingleLine
=>
$"when_on_single_line:
{
notificationString
}
"
,
_
=>
throw
new
NotSupportedException
(),
};
}
public
static
CodeStyleOption
<
AddImportPlacement
>
ParseUsingDirectivesPlacement
(
...
...
@@ -62,15 +61,12 @@ private static string GetExpressionBodyPreferenceEditorConfigString(CodeStyleOpt
// A notification value must be provided.
if
(
notificationOpt
!=
null
)
{
switch
(
value
)
return
value
switch
{
case
"inside_namespace"
:
return
new
CodeStyleOption
<
AddImportPlacement
>(
AddImportPlacement
.
InsideNamespace
,
notificationOpt
);
case
"outside_namespace"
:
return
new
CodeStyleOption
<
AddImportPlacement
>(
AddImportPlacement
.
OutsideNamespace
,
notificationOpt
);
default
:
throw
new
NotSupportedException
();
}
"inside_namespace"
=>
new
CodeStyleOption
<
AddImportPlacement
>(
AddImportPlacement
.
InsideNamespace
,
notificationOpt
),
"outside_namespace"
=>
new
CodeStyleOption
<
AddImportPlacement
>(
AddImportPlacement
.
OutsideNamespace
,
notificationOpt
),
_
=>
throw
new
NotSupportedException
(),
};
}
}
...
...
@@ -82,13 +78,12 @@ public static string GetUsingDirectivesPlacementEditorConfigString(CodeStyleOpti
Debug
.
Assert
(
value
.
Notification
!=
null
);
var
notificationString
=
value
.
Notification
.
ToEditorConfigString
();
switch
(
value
.
Value
)
return
value
.
Value
switch
{
case
AddImportPlacement
.
InsideNamespace
:
return
$"inside_namespace:
{
notificationString
}
"
;
case
AddImportPlacement
.
OutsideNamespace
:
return
$"outside_namespace:
{
notificationString
}
"
;
default
:
throw
new
NotSupportedException
();
}
AddImportPlacement
.
InsideNamespace
=>
$"inside_namespace:
{
notificationString
}
"
,
AddImportPlacement
.
OutsideNamespace
=>
$"outside_namespace:
{
notificationString
}
"
,
_
=>
throw
new
NotSupportedException
(),
};
}
private
static
CodeStyleOption
<
PreferBracesPreference
>
ParsePreferBracesPreference
(
...
...
@@ -124,20 +119,13 @@ private static string GetPreferBracesPreferenceEditorConfigString(CodeStyleOptio
Debug
.
Assert
(
value
.
Notification
!=
null
);
var
notificationString
=
value
.
Notification
.
ToEditorConfigString
();
switch
(
value
.
Value
)
return
value
.
Value
switch
{
case
PreferBracesPreference
.
None
:
return
$"false:
{
notificationString
}
"
;
case
PreferBracesPreference
.
WhenMultiline
:
return
$"when_multiline:
{
notificationString
}
"
;
case
PreferBracesPreference
.
Always
:
return
$"true:
{
notificationString
}
"
;
default
:
throw
ExceptionUtilities
.
Unreachable
;
}
PreferBracesPreference
.
None
=>
$"false:
{
notificationString
}
"
,
PreferBracesPreference
.
WhenMultiline
=>
$"when_multiline:
{
notificationString
}
"
,
PreferBracesPreference
.
Always
=>
$"true:
{
notificationString
}
"
,
_
=>
throw
ExceptionUtilities
.
Unreachable
,
};
}
}
}
src/Workspaces/CSharp/Portable/LanguageServices/CSharpTypeInferenceService.TypeInferrer.cs
浏览文件 @
1a01208c
此差异已折叠。
点击以展开。
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.State.cs
浏览文件 @
1a01208c
...
...
@@ -148,19 +148,13 @@ private bool IsInferredPredefinedType(SyntaxNode declarationStatement, SemanticM
}
private
TypeSyntax
GetTypeSyntaxFromDeclaration
(
SyntaxNode
declarationStatement
)
{
switch
(
declarationStatement
)
=>
declarationStatement
switch
{
case
VariableDeclarationSyntax
varDecl
:
return
varDecl
.
Type
;
case
ForEachStatementSyntax
forEach
:
return
forEach
.
Type
;
case
DeclarationExpressionSyntax
declExpr
:
return
declExpr
.
Type
;
}
return
null
;
}
VariableDeclarationSyntax
varDecl
=>
varDecl
.
Type
,
ForEachStatementSyntax
forEach
=>
forEach
.
Type
,
DeclarationExpressionSyntax
declExpr
=>
declExpr
.
Type
,
_
=>
null
,
};
private
UseVarPreference
GetCurrentTypeStylePreferences
(
OptionSet
optionSet
)
{
...
...
src/Workspaces/CSharp/Portable/Utilities/CSharpTypeStyleHelper.cs
浏览文件 @
1a01208c
...
...
@@ -83,23 +83,19 @@ internal TypeSyntax FindAnalyzableType(SyntaxNode node, SemanticModel semanticMo
{
Debug
.
Assert
(
node
.
IsKind
(
SyntaxKind
.
VariableDeclaration
,
SyntaxKind
.
ForEachStatement
,
SyntaxKind
.
DeclarationExpression
));
switch
(
node
)
return
node
switch
{
case
VariableDeclarationSyntax
variableDeclaration
:
return
ShouldAnalyzeVariableDeclaration
(
variableDeclaration
,
semanticModel
,
cancellationToken
)
?
variableDeclaration
.
Type
:
null
;
case
ForEachStatementSyntax
forEachStatement
:
return
ShouldAnalyzeForEachStatement
(
forEachStatement
,
semanticModel
,
cancellationToken
)
?
forEachStatement
.
Type
:
null
;
case
DeclarationExpressionSyntax
declarationExpression
:
return
ShouldAnalyzeDeclarationExpression
(
declarationExpression
,
semanticModel
,
cancellationToken
)
?
declarationExpression
.
Type
:
null
;
}
return
null
;
VariableDeclarationSyntax
variableDeclaration
=>
ShouldAnalyzeVariableDeclaration
(
variableDeclaration
,
semanticModel
,
cancellationToken
)
?
variableDeclaration
.
Type
:
null
,
ForEachStatementSyntax
forEachStatement
=>
ShouldAnalyzeForEachStatement
(
forEachStatement
,
semanticModel
,
cancellationToken
)
?
forEachStatement
.
Type
:
null
,
DeclarationExpressionSyntax
declarationExpression
=>
ShouldAnalyzeDeclarationExpression
(
declarationExpression
,
semanticModel
,
cancellationToken
)
?
declarationExpression
.
Type
:
null
,
_
=>
null
,
};
}
protected
virtual
bool
ShouldAnalyzeVariableDeclaration
(
VariableDeclarationSyntax
variableDeclaration
,
SemanticModel
semanticModel
,
CancellationToken
cancellationToken
)
...
...
src/Workspaces/Core/Portable/Workspace/Solution/MetadataOnlyImage.cs
浏览文件 @
1a01208c
...
...
@@ -101,10 +101,9 @@ public MetadataReference CreateReference(ImmutableArray<string> aliases, bool em
// first see whether we can use native memory directly.
var
stream
=
_storage
.
ReadStream
();
var
supportNativeMemory
=
stream
as
ISupportDirectMemoryAccess
;
AssemblyMetadata
metadata
;
if
(
s
upportNativeMemory
!=
null
)
if
(
s
tream
is
ISupportDirectMemoryAccess
supportNativeMemory
)
{
// this is unfortunate that if we give stream, compiler will just re-copy whole content to
// native memory again. this is a way to get around the issue by we getting native memory ourselves and then
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录