Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
110163ef
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,发现更多精彩内容 >>
提交
110163ef
编写于
7月 13, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Better respect lang version when generating expression bodies.
上级
d010af63
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
153 addition
and
50 deletion
+153
-50
src/EditorFeatures/CSharpTest/UseExpressionBody/Analyzer/UseExpressionBodyForMethodsAnalyzerTests.cs
...Body/Analyzer/UseExpressionBodyForMethodsAnalyzerTests.cs
+32
-0
src/Features/CSharp/Portable/ReplaceMethodWithProperty/CSharpReplaceMethodWithPropertyService.cs
...hodWithProperty/CSharpReplaceMethodWithPropertyService.cs
+2
-2
src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs
...rtyWithMethods/CSharpReplacePropertyWithMethodsService.cs
+2
-1
src/Features/CSharp/Portable/UseExpressionBody/Helpers/UseExpressionBodyForIndexersHelper.cs
...ressionBody/Helpers/UseExpressionBodyForIndexersHelper.cs
+13
-0
src/Features/CSharp/Portable/UseExpressionBody/Helpers/UseExpressionBodyForPropertiesHelper.cs
...ssionBody/Helpers/UseExpressionBodyForPropertiesHelper.cs
+3
-15
src/Features/CSharp/Portable/UseExpressionBody/Helpers/UseExpressionBodyHelper`1.cs
...le/UseExpressionBody/Helpers/UseExpressionBodyHelper`1.cs
+39
-3
src/Workspaces/CSharp/Portable/CodeGeneration/ConstructorGenerator.cs
...es/CSharp/Portable/CodeGeneration/ConstructorGenerator.cs
+2
-1
src/Workspaces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
...ces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
+2
-1
src/Workspaces/CSharp/Portable/CodeGeneration/MethodGenerator.cs
...kspaces/CSharp/Portable/CodeGeneration/MethodGenerator.cs
+2
-1
src/Workspaces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
...paces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
+2
-1
src/Workspaces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
...paces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
+15
-9
src/Workspaces/CSharp/Portable/Extensions/BlockSyntaxExtensions.cs
...paces/CSharp/Portable/Extensions/BlockSyntaxExtensions.cs
+39
-16
未找到文件。
src/EditorFeatures/CSharpTest/UseExpressionBody/Analyzer/UseExpressionBodyForMethodsAnalyzerTests.cs
浏览文件 @
110163ef
...
...
@@ -427,6 +427,38 @@ void M()
}"
,
options
:
UseExpressionBody
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp5
));
}
[
WorkItem
(
20352
,
"https://github.com/dotnet/roslyn/issues/20352"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExpressionBody
)]
public
async
Task
TestDoNotOfferToConvertToBlockIfExpressionBodyPreferredIfCSharp6
()
{
await
TestMissingAsync
(
@"
using System;
class C
{
void M() [|=>|] 0;
}"
,
new
TestParameters
(
options
:
UseExpressionBody
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp6
)));
}
[
WorkItem
(
20352
,
"https://github.com/dotnet/roslyn/issues/20352"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExpressionBody
)]
public
async
Task
TestOfferToConvertToExpressionIfCSharp6
()
{
await
TestAsync
(
@"
using System;
class C
{
void M() { [|return|] 0; }
}"
,
@"
using System;
class C
{
void M() => 0;
}"
,
options
:
UseExpressionBody
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp6
));
}
[
WorkItem
(
20362
,
"https://github.com/dotnet/roslyn/issues/20362"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseExpressionBody
)]
public
async
Task
TestOfferToConvertToBlockEvenIfExpressionBodyPreferredIfPriorToCSharp6_FixAll
()
...
...
src/Features/CSharp/Portable/ReplaceMethodWithProperty/CSharpReplaceMethodWithPropertyService.cs
浏览文件 @
110163ef
...
...
@@ -95,7 +95,7 @@ public void RemoveSetMethod(SyntaxEditor editor, SyntaxNode setMethodDeclaration
}
else
if
(
getAccessor
.
Body
!=
null
&&
getAccessor
.
Body
.
TryConvertToExpressionBody
(
parseOptions
,
expressionBodyPreference
,
p
ropertyDeclaration
.
Kind
(),
p
arseOptions
,
expressionBodyPreference
,
out
var
arrowExpression
,
out
var
semicolonToken
))
{
return
propertyDeclaration
.
WithExpressionBody
(
arrowExpression
)
...
...
@@ -183,7 +183,7 @@ private SyntaxToken GetPropertyName(SyntaxToken identifier, string propertyName,
if
(
accessorDeclaration
?.
Body
!=
null
&&
expressionBodyPreference
!=
ExpressionBodyPreference
.
Never
)
{
if
(
accessorDeclaration
.
Body
.
TryConvertToExpressionBody
(
parseOptions
,
expressionBodyPreference
,
accessorDeclaration
.
Kind
(),
parseOptions
,
expressionBodyPreference
,
out
var
arrowExpression
,
out
var
semicolonToken
))
{
return
accessorDeclaration
.
WithBody
(
null
)
...
...
src/Features/CSharp/Portable/ReplacePropertyWithMethods/CSharpReplacePropertyWithMethodsService.cs
浏览文件 @
110163ef
...
...
@@ -227,7 +227,8 @@ private static SyntaxTrivia ConvertDocumentationComment(SyntaxTrivia trivia, CSh
if
(
methodDeclaration
?.
Body
!=
null
&&
expressionBodyPreference
!=
ExpressionBodyPreference
.
Never
)
{
if
(
methodDeclaration
.
Body
.
TryConvertToExpressionBody
(
parseOptions
,
expressionBodyPreference
,
out
var
arrowExpression
,
out
var
semicolonToken
))
methodDeclaration
.
Kind
(),
parseOptions
,
expressionBodyPreference
,
out
var
arrowExpression
,
out
var
semicolonToken
))
{
return
methodDeclaration
.
WithBody
(
null
)
.
WithExpressionBody
(
arrowExpression
)
...
...
src/Features/CSharp/Portable/UseExpressionBody/Helpers/UseExpressionBodyForIndexersHelper.cs
浏览文件 @
110163ef
...
...
@@ -2,7 +2,9 @@
using
System
;
using
System.Collections.Immutable
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Options
;
...
...
@@ -58,5 +60,16 @@ protected override IndexerDeclarationSyntax WithBody(IndexerDeclarationSyntax de
}
protected
override
bool
CreateReturnStatementForExpression
(
IndexerDeclarationSyntax
declaration
)
=>
true
;
protected
override
bool
TryConvertToExpressionBody
(
IndexerDeclarationSyntax
declaration
,
ParseOptions
options
,
ExpressionBodyPreference
conversionPreference
,
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
return
this
.
TryConvertToExpressionBodyForBaseProperty
(
declaration
,
options
,
conversionPreference
,
out
arrowExpression
,
out
semicolonToken
);
}
}
}
src/Features/CSharp/Portable/UseExpressionBody/Helpers/UseExpressionBodyForPropertiesHelper.cs
浏览文件 @
110163ef
...
...
@@ -67,21 +67,9 @@ protected override PropertyDeclarationSyntax WithBody(PropertyDeclarationSyntax
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
if
(
base
.
TryConvertToExpressionBody
(
declaration
,
options
,
conversionPreference
,
out
arrowExpression
,
out
semicolonToken
))
{
return
true
;
}
var
getAccessor
=
GetSingleGetAccessor
(
declaration
.
AccessorList
);
if
(
getAccessor
?.
ExpressionBody
!=
null
&&
BlockSyntaxExtensions
.
MatchesPreference
(
getAccessor
.
ExpressionBody
.
Expression
,
conversionPreference
))
{
arrowExpression
=
SyntaxFactory
.
ArrowExpressionClause
(
getAccessor
.
ExpressionBody
.
Expression
);
semicolonToken
=
getAccessor
.
SemicolonToken
;
return
true
;
}
return
false
;
return
this
.
TryConvertToExpressionBodyForBaseProperty
(
declaration
,
options
,
conversionPreference
,
out
arrowExpression
,
out
semicolonToken
);
}
protected
override
Location
GetDiagnosticLocation
(
PropertyDeclarationSyntax
declaration
)
...
...
src/Features/CSharp/Portable/UseExpressionBody/Helpers/UseExpressionBodyHelper`1.cs
浏览文件 @
110163ef
...
...
@@ -111,13 +111,48 @@ protected virtual Location GetDiagnosticLocation(TDeclaration declaration)
ParseOptions
options
,
ExpressionBodyPreference
conversionPreference
,
out
ArrowExpressionClauseSyntax
expressionWhenOnSingleLine
,
out
SyntaxToken
semicolonWhenOnSingleLine
)
{
return
TryConvertToExpressionBodyWorker
(
declaration
,
options
,
conversionPreference
,
out
expressionWhenOnSingleLine
,
out
semicolonWhenOnSingleLine
);
}
private
bool
TryConvertToExpressionBodyWorker
(
SyntaxNode
declaration
,
ParseOptions
options
,
ExpressionBodyPreference
conversionPreference
,
out
ArrowExpressionClauseSyntax
expressionWhenOnSingleLine
,
out
SyntaxToken
semicolonWhenOnSingleLine
)
{
var
body
=
this
.
GetBody
(
declaration
);
return
body
.
TryConvertToExpressionBody
(
options
,
conversionPreference
,
return
body
.
TryConvertToExpressionBody
(
declaration
.
Kind
(),
options
,
conversionPreference
,
out
expressionWhenOnSingleLine
,
out
semicolonWhenOnSingleLine
);
}
protected
bool
TryConvertToExpressionBodyForBaseProperty
(
BasePropertyDeclarationSyntax
declaration
,
ParseOptions
options
,
ExpressionBodyPreference
conversionPreference
,
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
if
(
this
.
TryConvertToExpressionBodyWorker
(
declaration
,
options
,
conversionPreference
,
out
arrowExpression
,
out
semicolonToken
))
{
return
true
;
}
var
getAccessor
=
GetSingleGetAccessor
(
declaration
.
AccessorList
);
if
(
getAccessor
?.
ExpressionBody
!=
null
&&
BlockSyntaxExtensions
.
MatchesPreference
(
getAccessor
.
ExpressionBody
.
Expression
,
conversionPreference
))
{
arrowExpression
=
SyntaxFactory
.
ArrowExpressionClause
(
getAccessor
.
ExpressionBody
.
Expression
);
semicolonToken
=
getAccessor
.
SemicolonToken
;
return
true
;
}
return
false
;
}
public
(
bool
canOffer
,
bool
fixesError
)
CanOfferUseBlockBody
(
OptionSet
optionSet
,
TDeclaration
declaration
,
bool
forAnalyzer
)
{
...
...
@@ -171,8 +206,9 @@ protected virtual Location GetDiagnosticLocation(TDeclaration declaration)
{
if
(
useExpressionBody
)
{
TryConvertToExpressionBody
(
declaration
,
declaration
.
SyntaxTree
.
Options
,
ExpressionBodyPreference
.
WhenPossible
,
out
var
expressionBody
,
out
var
semicolonToken
);
TryConvertToExpressionBody
(
declaration
,
declaration
.
SyntaxTree
.
Options
,
ExpressionBodyPreference
.
WhenPossible
,
out
var
expressionBody
,
out
var
semicolonToken
);
var
trailingTrivia
=
semicolonToken
.
TrailingTrivia
.
Where
(
t
=>
t
.
Kind
()
!=
SyntaxKind
.
EndOfLineTrivia
)
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/ConstructorGenerator.cs
浏览文件 @
110163ef
...
...
@@ -74,7 +74,8 @@ private static MemberDeclarationSyntax LastConstructorOrField(SyntaxList<MemberD
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedConstructors
).
Value
;
if
(
declaration
.
Body
.
TryConvertToExpressionBody
(
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
declaration
.
Kind
(),
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
{
return
declaration
.
WithBody
(
null
)
.
WithExpressionBody
(
expressionBody
)
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
浏览文件 @
110163ef
...
...
@@ -86,7 +86,8 @@ internal static class ConversionGenerator
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedOperators
).
Value
;
if
(
declaration
.
Body
.
TryConvertToExpressionBody
(
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
declaration
.
Kind
(),
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
{
return
declaration
.
WithBody
(
null
)
.
WithExpressionBody
(
expressionBody
)
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/MethodGenerator.cs
浏览文件 @
110163ef
...
...
@@ -119,7 +119,8 @@ internal static class MethodGenerator
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedMethods
).
Value
;
if
(
methodDeclaration
.
Body
.
TryConvertToExpressionBody
(
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
methodDeclaration
.
Kind
(),
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
{
return
methodDeclaration
.
WithBody
(
null
)
.
WithExpressionBody
(
expressionBody
)
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
浏览文件 @
110163ef
...
...
@@ -58,7 +58,8 @@ internal static class OperatorGenerator
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedOperators
).
Value
;
if
(
declaration
.
Body
.
TryConvertToExpressionBody
(
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
declaration
.
Kind
(),
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
{
return
declaration
.
WithBody
(
null
)
.
WithExpressionBody
(
expressionBody
)
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
浏览文件 @
110163ef
...
...
@@ -146,16 +146,19 @@ private static TypeSyntax GeneratePropertyType(IPropertySymbol property)
}
private
static
bool
TryGetExpressionBody
(
AccessorListSyntax
accessorList
,
ParseOptions
options
,
ExpressionBodyPreference
preference
,
BasePropertyDeclarationSyntax
baseProperty
,
ParseOptions
options
,
ExpressionBodyPreference
preference
,
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
var
accessorList
=
baseProperty
.
AccessorList
;
if
(
preference
!=
ExpressionBodyPreference
.
Never
&&
accessorList
.
Accessors
.
Count
==
1
)
{
var
accessor
=
accessorList
.
Accessors
[
0
];
if
(
accessor
.
IsKind
(
SyntaxKind
.
GetAccessorDeclaration
))
{
return
TryGetExpressionBody
(
accessor
,
options
,
preference
,
out
arrowExpression
,
out
semicolonToken
);
return
TryGetExpressionBody
(
baseProperty
.
Kind
(),
accessor
,
options
,
preference
,
out
arrowExpression
,
out
semicolonToken
);
}
}
...
...
@@ -172,8 +175,9 @@ private static TypeSyntax GeneratePropertyType(IPropertySymbol property)
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedProperties
).
Value
;
if
(
declaration
.
Initializer
==
null
)
{
if
(
TryGetExpressionBody
(
declaration
.
AccessorList
,
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
if
(
TryGetExpressionBody
(
declaration
,
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
{
declaration
=
declaration
.
WithAccessorList
(
null
)
.
WithExpressionBody
(
expressionBody
)
...
...
@@ -191,8 +195,9 @@ private static TypeSyntax GeneratePropertyType(IPropertySymbol property)
if
(
declaration
.
ExpressionBody
==
null
)
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedIndexers
).
Value
;
if
(
TryGetExpressionBody
(
declaration
.
AccessorList
,
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
if
(
TryGetExpressionBody
(
declaration
,
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
{
declaration
=
declaration
.
WithAccessorList
(
null
)
.
WithExpressionBody
(
expressionBody
)
...
...
@@ -210,7 +215,8 @@ private static TypeSyntax GeneratePropertyType(IPropertySymbol property)
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedAccessors
).
Value
;
if
(
declaration
.
Body
.
TryConvertToExpressionBody
(
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
declaration
.
Kind
(),
options
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
{
declaration
=
declaration
.
WithBody
(
null
)
.
WithExpressionBody
(
expressionBody
)
...
...
@@ -222,7 +228,7 @@ private static TypeSyntax GeneratePropertyType(IPropertySymbol property)
}
private
static
bool
TryGetExpressionBody
(
AccessorDeclarationSyntax
accessor
,
ParseOptions
options
,
ExpressionBodyPreference
preference
,
SyntaxKind
declaratoinKind
,
AccessorDeclarationSyntax
accessor
,
ParseOptions
options
,
ExpressionBodyPreference
preference
,
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
// If the accessor has an expression body already, then use that as the expression body
...
...
@@ -235,7 +241,7 @@ private static TypeSyntax GeneratePropertyType(IPropertySymbol property)
}
return
accessor
.
Body
.
TryConvertToExpressionBody
(
options
,
preference
,
out
arrowExpression
,
out
semicolonToken
);
declaratoinKind
,
options
,
preference
,
out
arrowExpression
,
out
semicolonToken
);
}
private
static
AccessorListSyntax
GenerateAccessorList
(
...
...
src/Workspaces/CSharp/Portable/Extensions/BlockSyntaxExtensions.cs
浏览文件 @
110163ef
...
...
@@ -13,29 +13,36 @@ namespace Microsoft.CodeAnalysis.CSharp.Extensions
internal
static
class
BlockSyntaxExtensions
{
public
static
bool
TryConvertToExpressionBody
(
this
BlockSyntax
block
,
ParseOptions
options
,
ExpressionBodyPreference
preference
,
this
BlockSyntax
block
,
SyntaxKind
declarationKind
,
ParseOptions
options
,
ExpressionBodyPreference
preference
,
out
ArrowExpressionClauseSyntax
arrowExpression
,
out
SyntaxToken
semicolonToken
)
{
if
(
preference
!=
ExpressionBodyPreference
.
Never
&&
(
options
as
CSharpParseOptions
)?.
LanguageVersion
>=
LanguageVersion
.
CSharp7
)
if
(
preference
!=
ExpressionBodyPreference
.
Never
)
{
if
(
block
!=
null
&&
block
.
Statements
.
Count
==
1
)
{
var
firstStatement
=
block
.
Statements
[
0
];
var
csharpOptions
=
(
CSharpParseOptions
)
options
;
var
acceptableVersion
=
csharpOptions
.
LanguageVersion
>=
LanguageVersion
.
CSharp7
||
(
csharpOptions
.
LanguageVersion
>=
LanguageVersion
.
CSharp6
&&
!
RequiresCSharp7
(
declarationKind
));
if
(
TryGetExpression
(
firstStatement
,
out
var
expression
,
out
semicolonToken
)
&&
MatchesPreference
(
expression
,
preference
))
if
(
acceptableVersion
)
{
if
(
block
!=
null
&&
block
.
Statements
.
Count
==
1
)
{
arrowExpression
=
SyntaxFactory
.
ArrowExpressionClause
(
expression
);
var
firstStatement
=
block
.
Statements
[
0
];
if
(
TryGetExpression
(
firstStatement
,
out
var
expression
,
out
semicolonToken
)
&&
MatchesPreference
(
expression
,
preference
))
{
arrowExpression
=
SyntaxFactory
.
ArrowExpressionClause
(
expression
);
// The close brace of the block may have important trivia on it (like
// comments or directives). Preserve them on the semicolon when we
// convert to an expression body.
semicolonToken
=
semicolonToken
.
WithAppendedTrailingTrivia
(
block
.
CloseBraceToken
.
LeadingTrivia
.
Where
(
t
=>
!
t
.
IsWhitespaceOrEndOfLine
()));
return
true
;
// The close brace of the block may have important trivia on it (like
// comments or directives). Preserve them on the semicolon when we
// convert to an expression body.
semicolonToken
=
semicolonToken
.
WithAppendedTrailingTrivia
(
block
.
CloseBraceToken
.
LeadingTrivia
.
Where
(
t
=>
!
t
.
IsWhitespaceOrEndOfLine
()));
return
true
;
}
}
}
}
...
...
@@ -45,6 +52,22 @@ internal static class BlockSyntaxExtensions
return
false
;
}
private
static
bool
RequiresCSharp7
(
SyntaxKind
declarationKind
)
{
switch
(
declarationKind
)
{
case
SyntaxKind
.
ConstructorDeclaration
:
case
SyntaxKind
.
DestructorDeclaration
:
case
SyntaxKind
.
AddAccessorDeclaration
:
case
SyntaxKind
.
RemoveAccessorDeclaration
:
case
SyntaxKind
.
GetAccessorDeclaration
:
case
SyntaxKind
.
SetAccessorDeclaration
:
return
true
;
}
return
false
;
}
public
static
bool
MatchesPreference
(
ExpressionSyntax
expression
,
ExpressionBodyPreference
preference
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录