Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
e0f1c9ea
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,发现更多精彩内容 >>
提交
e0f1c9ea
编写于
7月 24, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Initial work to use new test library.
上级
11e3c508
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
550 addition
and
265 deletion
+550
-265
src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs
...omMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs
+444
-155
src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionTest.cs
...osticsTestUtilities/CodeActions/AbstractCodeActionTest.cs
+37
-26
src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeAction.cs
...HashCodeFromMembers/GenerateEqualsAndGetHashCodeAction.cs
+3
-1
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
...rp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
+9
-9
src/Workspaces/CSharp/Portable/CodeGeneration/ConstructorGenerator.cs
...es/CSharp/Portable/CodeGeneration/ConstructorGenerator.cs
+5
-8
src/Workspaces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
...ces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
+6
-10
src/Workspaces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
...paces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
+23
-26
src/Workspaces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
...paces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
+23
-30
未找到文件。
src/EditorFeatures/CSharpTest/GenerateFromMembers/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeFromMembersTests.cs
浏览文件 @
e0f1c9ea
此差异已折叠。
点击以展开。
src/EditorFeatures/DiagnosticsTestUtilities/CodeActions/AbstractCodeActionTest.cs
浏览文件 @
e0f1c9ea
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
using
System
;
using
System
;
using
System.Collections.Generic
;
using
System.Collections.Generic
;
using
System.Collections.Immutable
;
using
System.Collections.Immutable
;
using
System.Composition
;
using
System.Diagnostics
;
using
System.Diagnostics
;
using
System.Linq
;
using
System.Linq
;
using
System.Threading
;
using
System.Threading
;
...
@@ -14,6 +15,7 @@
...
@@ -14,6 +15,7 @@
using
Microsoft.CodeAnalysis.CodeRefactorings
;
using
Microsoft.CodeAnalysis.CodeRefactorings
;
using
Microsoft.CodeAnalysis.Editor.Implementation.Preview
;
using
Microsoft.CodeAnalysis.Editor.Implementation.Preview
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.PickMembers
;
using
Microsoft.CodeAnalysis.PickMembers
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.PooledObjects
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
using
Microsoft.CodeAnalysis.Shared.Utilities
;
...
@@ -114,32 +116,6 @@ protected override Task<ImmutableArray<Diagnostic>> GetDiagnosticsWorkerAsync(Te
...
@@ -114,32 +116,6 @@ protected override Task<ImmutableArray<Diagnostic>> GetDiagnosticsWorkerAsync(Te
protected
static
Document
GetDocument
(
TestWorkspace
workspace
)
protected
static
Document
GetDocument
(
TestWorkspace
workspace
)
=>
workspace
.
CurrentSolution
.
GetDocument
(
workspace
.
Documents
.
First
().
Id
);
=>
workspace
.
CurrentSolution
.
GetDocument
(
workspace
.
Documents
.
First
().
Id
);
private
class
TestPickMembersService
:
IPickMembersService
{
private
readonly
ImmutableArray
<
string
>
_memberNames
;
private
readonly
Action
<
ImmutableArray
<
PickMembersOption
>>
_optionsCallback
;
public
TestPickMembersService
(
ImmutableArray
<
string
>
memberNames
,
Action
<
ImmutableArray
<
PickMembersOption
>>
optionsCallback
)
{
_memberNames
=
memberNames
;
_optionsCallback
=
optionsCallback
;
}
public
PickMembersResult
PickMembers
(
string
title
,
ImmutableArray
<
ISymbol
>
members
,
ImmutableArray
<
PickMembersOption
>
options
)
{
_optionsCallback
?.
Invoke
(
options
);
return
new
PickMembersResult
(
_memberNames
.
IsDefault
?
members
:
_memberNames
.
SelectAsArray
(
n
=>
members
.
Single
(
m
=>
m
.
Name
==
n
)),
options
);
}
}
internal
static
void
EnableOptions
(
internal
static
void
EnableOptions
(
ImmutableArray
<
PickMembersOption
>
options
,
ImmutableArray
<
PickMembersOption
>
options
,
params
string
[]
ids
)
params
string
[]
ids
)
...
@@ -174,4 +150,39 @@ internal static void EnableOption(ImmutableArray<PickMembersOption> options, str
...
@@ -174,4 +150,39 @@ internal static void EnableOption(ImmutableArray<PickMembersOption> options, str
parameters
.
WithFixProviderData
(
pickMembersService
));
parameters
.
WithFixProviderData
(
pickMembersService
));
}
}
}
}
[
ExportWorkspaceService
(
typeof
(
IPickMembersService
),
ServiceLayer
.
Host
),
Shared
,
PartNotDiscoverable
]
internal
class
TestPickMembersService
:
IPickMembersService
{
public
ImmutableArray
<
string
>
MemberNames
;
public
Action
<
ImmutableArray
<
PickMembersOption
>>
OptionsCallback
;
[
ImportingConstructor
]
[
Obsolete
(
MefConstruction
.
ImportingConstructorMessage
,
error
:
true
)]
public
TestPickMembersService
()
{
}
#pragma warning disable RS0034 // Exported parts should be marked with 'ImportingConstructorAttribute'
public
TestPickMembersService
(
ImmutableArray
<
string
>
memberNames
,
Action
<
ImmutableArray
<
PickMembersOption
>>
optionsCallback
)
{
MemberNames
=
memberNames
;
OptionsCallback
=
optionsCallback
;
}
#pragma warning restore RS0034 // Exported parts should be marked with 'ImportingConstructorAttribute'
public
PickMembersResult
PickMembers
(
string
title
,
ImmutableArray
<
ISymbol
>
members
,
ImmutableArray
<
PickMembersOption
>
options
)
{
OptionsCallback
?.
Invoke
(
options
);
return
new
PickMembersResult
(
MemberNames
.
IsDefault
?
members
:
MemberNames
.
SelectAsArray
(
n
=>
members
.
Single
(
m
=>
m
.
Name
==
n
)),
options
);
}
}
}
}
src/Features/Core/Portable/GenerateEqualsAndGetHashCodeFromMembers/GenerateEqualsAndGetHashCodeAction.cs
浏览文件 @
e0f1c9ea
...
@@ -80,8 +80,10 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
...
@@ -80,8 +80,10 @@ protected override async Task<Document> GetChangedDocumentAsync(CancellationToke
await
AddOperatorsAsync
(
methods
,
cancellationToken
).
ConfigureAwait
(
false
);
await
AddOperatorsAsync
(
methods
,
cancellationToken
).
ConfigureAwait
(
false
);
}
}
var
options
=
await
_document
.
GetOptionsAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
newTypeDeclaration
=
CodeGenerator
.
AddMemberDeclarations
(
var
newTypeDeclaration
=
CodeGenerator
.
AddMemberDeclarations
(
_typeDeclaration
,
methods
,
_document
.
Project
.
Solution
.
Workspace
);
_typeDeclaration
,
methods
,
_document
.
Project
.
Solution
.
Workspace
,
new
CodeGenerationOptions
(
options
:
options
));
if
(
constructedTypeToImplement
is
object
)
if
(
constructedTypeToImplement
is
object
)
{
{
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpCodeGenerationService.cs
浏览文件 @
e0f1c9ea
...
@@ -139,7 +139,7 @@ protected override TDeclarationNode AddMethod<TDeclarationNode>(TDeclarationNode
...
@@ -139,7 +139,7 @@ protected override TDeclarationNode AddMethod<TDeclarationNode>(TDeclarationNode
if
(
method
.
IsConstructor
())
if
(
method
.
IsConstructor
())
{
{
return
Cast
<
TDeclarationNode
>(
ConstructorGenerator
.
AddConstructorTo
(
return
Cast
<
TDeclarationNode
>(
ConstructorGenerator
.
AddConstructorTo
(
typeDeclaration
,
method
,
Workspace
,
options
,
availableIndices
));
typeDeclaration
,
method
,
options
,
availableIndices
));
}
}
if
(
method
.
IsDestructor
())
if
(
method
.
IsDestructor
())
...
@@ -150,13 +150,13 @@ protected override TDeclarationNode AddMethod<TDeclarationNode>(TDeclarationNode
...
@@ -150,13 +150,13 @@ protected override TDeclarationNode AddMethod<TDeclarationNode>(TDeclarationNode
if
(
method
.
MethodKind
==
MethodKind
.
Conversion
)
if
(
method
.
MethodKind
==
MethodKind
.
Conversion
)
{
{
return
Cast
<
TDeclarationNode
>(
ConversionGenerator
.
AddConversionTo
(
return
Cast
<
TDeclarationNode
>(
ConversionGenerator
.
AddConversionTo
(
typeDeclaration
,
method
,
Workspace
,
options
,
availableIndices
));
typeDeclaration
,
method
,
options
,
availableIndices
));
}
}
if
(
method
.
MethodKind
==
MethodKind
.
UserDefinedOperator
)
if
(
method
.
MethodKind
==
MethodKind
.
UserDefinedOperator
)
{
{
return
Cast
<
TDeclarationNode
>(
OperatorGenerator
.
AddOperatorTo
(
return
Cast
<
TDeclarationNode
>(
OperatorGenerator
.
AddOperatorTo
(
typeDeclaration
,
method
,
Workspace
,
options
,
availableIndices
));
typeDeclaration
,
method
,
options
,
availableIndices
));
}
}
return
Cast
<
TDeclarationNode
>(
MethodGenerator
.
AddMethodTo
(
return
Cast
<
TDeclarationNode
>(
MethodGenerator
.
AddMethodTo
(
...
@@ -229,12 +229,12 @@ protected override TDeclarationNode AddProperty<TDeclarationNode>(TDeclarationNo
...
@@ -229,12 +229,12 @@ protected override TDeclarationNode AddProperty<TDeclarationNode>(TDeclarationNo
if
(
destination
is
TypeDeclarationSyntax
)
if
(
destination
is
TypeDeclarationSyntax
)
{
{
return
Cast
<
TDeclarationNode
>(
PropertyGenerator
.
AddPropertyTo
(
return
Cast
<
TDeclarationNode
>(
PropertyGenerator
.
AddPropertyTo
(
Cast
<
TypeDeclarationSyntax
>(
destination
),
property
,
Workspace
,
options
,
availableIndices
));
Cast
<
TypeDeclarationSyntax
>(
destination
),
property
,
options
,
availableIndices
));
}
}
else
else
{
{
return
Cast
<
TDeclarationNode
>(
PropertyGenerator
.
AddPropertyTo
(
return
Cast
<
TDeclarationNode
>(
PropertyGenerator
.
AddPropertyTo
(
Cast
<
CompilationUnitSyntax
>(
destination
),
property
,
Workspace
,
options
,
availableIndices
));
Cast
<
CompilationUnitSyntax
>(
destination
),
property
,
options
,
availableIndices
));
}
}
}
}
...
@@ -587,17 +587,17 @@ public override SyntaxNode CreateFieldDeclaration(IFieldSymbol field, CodeGenera
...
@@ -587,17 +587,17 @@ public override SyntaxNode CreateFieldDeclaration(IFieldSymbol field, CodeGenera
if
(
method
.
IsConstructor
())
if
(
method
.
IsConstructor
())
{
{
return
ConstructorGenerator
.
GenerateConstructorDeclaration
(
return
ConstructorGenerator
.
GenerateConstructorDeclaration
(
method
,
Workspace
,
options
,
options
.
ParseOptions
);
method
,
options
,
options
.
ParseOptions
);
}
}
else
if
(
method
.
IsUserDefinedOperator
())
else
if
(
method
.
IsUserDefinedOperator
())
{
{
return
OperatorGenerator
.
GenerateOperatorDeclaration
(
return
OperatorGenerator
.
GenerateOperatorDeclaration
(
method
,
Workspace
,
options
,
options
.
ParseOptions
);
method
,
options
,
options
.
ParseOptions
);
}
}
else
if
(
method
.
IsConversion
())
else
if
(
method
.
IsConversion
())
{
{
return
ConversionGenerator
.
GenerateConversionDeclaration
(
return
ConversionGenerator
.
GenerateConversionDeclaration
(
method
,
Workspace
,
options
,
options
.
ParseOptions
);
method
,
options
,
options
.
ParseOptions
);
}
}
else
if
(
method
.
IsLocalFunction
())
else
if
(
method
.
IsLocalFunction
())
{
{
...
@@ -615,7 +615,7 @@ public override SyntaxNode CreateFieldDeclaration(IFieldSymbol field, CodeGenera
...
@@ -615,7 +615,7 @@ public override SyntaxNode CreateFieldDeclaration(IFieldSymbol field, CodeGenera
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
CodeGenerationOptions
options
)
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
CodeGenerationOptions
options
)
{
{
return
PropertyGenerator
.
GeneratePropertyOrIndexer
(
return
PropertyGenerator
.
GeneratePropertyOrIndexer
(
property
,
destination
,
Workspace
,
options
,
options
.
ParseOptions
);
property
,
destination
,
options
,
options
.
ParseOptions
);
}
}
public
override
SyntaxNode
CreateNamedTypeDeclaration
(
public
override
SyntaxNode
CreateNamedTypeDeclaration
(
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/ConstructorGenerator.cs
浏览文件 @
e0f1c9ea
...
@@ -24,13 +24,11 @@ private static MemberDeclarationSyntax LastConstructorOrField(SyntaxList<MemberD
...
@@ -24,13 +24,11 @@ private static MemberDeclarationSyntax LastConstructorOrField(SyntaxList<MemberD
internal
static
TypeDeclarationSyntax
AddConstructorTo
(
internal
static
TypeDeclarationSyntax
AddConstructorTo
(
TypeDeclarationSyntax
destination
,
TypeDeclarationSyntax
destination
,
IMethodSymbol
constructor
,
IMethodSymbol
constructor
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
IList
<
bool
>
availableIndices
)
IList
<
bool
>
availableIndices
)
{
{
var
constructorDeclaration
=
GenerateConstructorDeclaration
(
var
constructorDeclaration
=
GenerateConstructorDeclaration
(
constructor
,
workspace
,
options
,
constructor
,
options
,
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
// Generate after the last constructor, or after the last field, or at the start of the
// Generate after the last constructor, or after the last field, or at the start of the
// type.
// type.
...
@@ -42,7 +40,6 @@ private static MemberDeclarationSyntax LastConstructorOrField(SyntaxList<MemberD
...
@@ -42,7 +40,6 @@ private static MemberDeclarationSyntax LastConstructorOrField(SyntaxList<MemberD
internal
static
ConstructorDeclarationSyntax
GenerateConstructorDeclaration
(
internal
static
ConstructorDeclarationSyntax
GenerateConstructorDeclaration
(
IMethodSymbol
constructor
,
IMethodSymbol
constructor
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
...
@@ -65,20 +62,20 @@ private static MemberDeclarationSyntax LastConstructorOrField(SyntaxList<MemberD
...
@@ -65,20 +62,20 @@ private static MemberDeclarationSyntax LastConstructorOrField(SyntaxList<MemberD
body
:
hasNoBody
?
null
:
GenerateBlock
(
constructor
),
body
:
hasNoBody
?
null
:
GenerateBlock
(
constructor
),
semicolonToken
:
hasNoBody
?
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
)
:
default
);
semicolonToken
:
hasNoBody
?
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
)
:
default
);
declaration
=
UseExpressionBodyIfDesired
(
workspace
,
declaration
,
parseOptions
);
declaration
=
UseExpressionBodyIfDesired
(
options
,
declaration
,
parseOptions
);
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
ConditionallyAddDocumentationCommentTo
(
declaration
,
constructor
,
options
));
ConditionallyAddDocumentationCommentTo
(
declaration
,
constructor
,
options
));
}
}
private
static
ConstructorDeclarationSyntax
UseExpressionBodyIfDesired
(
private
static
ConstructorDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
ConstructorDeclarationSyntax
declaration
,
ParseOptions
o
ptions
)
CodeGenerationOptions
options
,
ConstructorDeclarationSyntax
declaration
,
ParseOptions
parseO
ptions
)
{
{
if
(
declaration
.
ExpressionBody
==
null
)
if
(
declaration
.
ExpressionBody
==
null
)
{
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedConstructors
).
Value
;
var
expressionBodyPreference
=
options
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedConstructors
).
Value
;
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
declaration
.
Kind
(),
o
ptions
,
expressionBodyPreference
,
declaration
.
Kind
(),
parseO
ptions
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
out
var
expressionBody
,
out
var
semicolonToken
))
{
{
return
declaration
.
WithBody
(
null
)
return
declaration
.
WithBody
(
null
)
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
浏览文件 @
e0f1c9ea
...
@@ -18,13 +18,11 @@ internal static class ConversionGenerator
...
@@ -18,13 +18,11 @@ internal static class ConversionGenerator
internal
static
TypeDeclarationSyntax
AddConversionTo
(
internal
static
TypeDeclarationSyntax
AddConversionTo
(
TypeDeclarationSyntax
destination
,
TypeDeclarationSyntax
destination
,
IMethodSymbol
method
,
IMethodSymbol
method
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
IList
<
bool
>
availableIndices
)
IList
<
bool
>
availableIndices
)
{
{
var
methodDeclaration
=
GenerateConversionDeclaration
(
var
methodDeclaration
=
GenerateConversionDeclaration
(
method
,
workspace
,
options
,
method
,
options
,
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
var
members
=
Insert
(
destination
.
Members
,
methodDeclaration
,
options
,
availableIndices
,
after
:
LastOperator
);
var
members
=
Insert
(
destination
.
Members
,
methodDeclaration
,
options
,
availableIndices
,
after
:
LastOperator
);
...
@@ -33,18 +31,16 @@ internal static class ConversionGenerator
...
@@ -33,18 +31,16 @@ internal static class ConversionGenerator
internal
static
ConversionOperatorDeclarationSyntax
GenerateConversionDeclaration
(
internal
static
ConversionOperatorDeclarationSyntax
GenerateConversionDeclaration
(
IMethodSymbol
method
,
IMethodSymbol
method
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
var
declaration
=
GenerateConversionDeclarationWorker
(
method
,
workspace
,
options
,
parseOptions
);
var
declaration
=
GenerateConversionDeclarationWorker
(
method
,
options
,
parseOptions
);
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
AddAnnotationsTo
(
method
,
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
AddAnnotationsTo
(
method
,
ConditionallyAddDocumentationCommentTo
(
declaration
,
method
,
options
)));
ConditionallyAddDocumentationCommentTo
(
declaration
,
method
,
options
)));
}
}
private
static
ConversionOperatorDeclarationSyntax
GenerateConversionDeclarationWorker
(
private
static
ConversionOperatorDeclarationSyntax
GenerateConversionDeclarationWorker
(
IMethodSymbol
method
,
IMethodSymbol
method
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
...
@@ -70,20 +66,20 @@ internal static class ConversionGenerator
...
@@ -70,20 +66,20 @@ internal static class ConversionGenerator
body
:
hasNoBody
?
null
:
StatementGenerator
.
GenerateBlock
(
method
),
body
:
hasNoBody
?
null
:
StatementGenerator
.
GenerateBlock
(
method
),
semicolonToken
:
hasNoBody
?
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
)
:
new
SyntaxToken
());
semicolonToken
:
hasNoBody
?
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
)
:
new
SyntaxToken
());
declaration
=
UseExpressionBodyIfDesired
(
workspace
,
declaration
,
parseOptions
);
declaration
=
UseExpressionBodyIfDesired
(
options
,
declaration
,
parseOptions
);
return
declaration
;
return
declaration
;
}
}
private
static
ConversionOperatorDeclarationSyntax
UseExpressionBodyIfDesired
(
private
static
ConversionOperatorDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
ConversionOperatorDeclarationSyntax
declaration
,
ParseOptions
o
ptions
)
CodeGenerationOptions
options
,
ConversionOperatorDeclarationSyntax
declaration
,
ParseOptions
parseO
ptions
)
{
{
if
(
declaration
.
ExpressionBody
==
null
)
if
(
declaration
.
ExpressionBody
==
null
)
{
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedOperators
).
Value
;
var
expressionBodyPreference
=
options
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedOperators
).
Value
;
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
declaration
.
Kind
(),
o
ptions
,
expressionBodyPreference
,
declaration
.
Kind
(),
parseO
ptions
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
out
var
expressionBody
,
out
var
semicolonToken
))
{
{
return
declaration
.
WithBody
(
null
)
return
declaration
.
WithBody
(
null
)
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
浏览文件 @
e0f1c9ea
...
@@ -19,13 +19,11 @@ internal static class OperatorGenerator
...
@@ -19,13 +19,11 @@ internal static class OperatorGenerator
internal
static
TypeDeclarationSyntax
AddOperatorTo
(
internal
static
TypeDeclarationSyntax
AddOperatorTo
(
TypeDeclarationSyntax
destination
,
TypeDeclarationSyntax
destination
,
IMethodSymbol
method
,
IMethodSymbol
method
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
IList
<
bool
>
availableIndices
)
IList
<
bool
>
availableIndices
)
{
{
var
methodDeclaration
=
GenerateOperatorDeclaration
(
var
methodDeclaration
=
GenerateOperatorDeclaration
(
method
,
workspace
,
options
,
method
,
options
,
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
var
members
=
Insert
(
destination
.
Members
,
methodDeclaration
,
options
,
availableIndices
,
after
:
LastOperator
);
var
members
=
Insert
(
destination
.
Members
,
methodDeclaration
,
options
,
availableIndices
,
after
:
LastOperator
);
...
@@ -34,7 +32,6 @@ internal static class OperatorGenerator
...
@@ -34,7 +32,6 @@ internal static class OperatorGenerator
internal
static
OperatorDeclarationSyntax
GenerateOperatorDeclaration
(
internal
static
OperatorDeclarationSyntax
GenerateOperatorDeclaration
(
IMethodSymbol
method
,
IMethodSymbol
method
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
...
@@ -45,20 +42,20 @@ internal static class OperatorGenerator
...
@@ -45,20 +42,20 @@ internal static class OperatorGenerator
}
}
var
declaration
=
GenerateOperatorDeclarationWorker
(
method
,
options
,
parseOptions
);
var
declaration
=
GenerateOperatorDeclarationWorker
(
method
,
options
,
parseOptions
);
declaration
=
UseExpressionBodyIfDesired
(
workspace
,
declaration
,
parseOptions
);
declaration
=
UseExpressionBodyIfDesired
(
options
,
declaration
,
parseOptions
);
return
AddAnnotationsTo
(
method
,
return
AddAnnotationsTo
(
method
,
ConditionallyAddDocumentationCommentTo
(
declaration
,
method
,
options
));
ConditionallyAddDocumentationCommentTo
(
declaration
,
method
,
options
));
}
}
private
static
OperatorDeclarationSyntax
UseExpressionBodyIfDesired
(
private
static
OperatorDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
OperatorDeclarationSyntax
declaration
,
ParseOptions
o
ptions
)
CodeGenerationOptions
options
,
OperatorDeclarationSyntax
declaration
,
ParseOptions
parseO
ptions
)
{
{
if
(
declaration
.
ExpressionBody
==
null
)
if
(
declaration
.
ExpressionBody
==
null
)
{
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedOperators
).
Value
;
var
expressionBodyPreference
=
options
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedOperators
).
Value
;
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
declaration
.
Kind
(),
o
ptions
,
expressionBodyPreference
,
declaration
.
Kind
(),
parseO
ptions
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
out
var
expressionBody
,
out
var
semicolonToken
))
{
{
return
declaration
.
WithBody
(
null
)
return
declaration
.
WithBody
(
null
)
...
@@ -99,24 +96,24 @@ internal static class OperatorGenerator
...
@@ -99,24 +96,24 @@ internal static class OperatorGenerator
return
operatorDecl
;
return
operatorDecl
;
}
}
private
static
OperatorDeclarationSyntax
UseExpressionBodyIfDesired
(
//
private static OperatorDeclarationSyntax UseExpressionBodyIfDesired(
CodeGenerationOptions
options
,
OperatorDeclarationSyntax
operatorDeclaration
,
ParseOptions
parseOptions
)
//
CodeGenerationOptions options, OperatorDeclarationSyntax operatorDeclaration, ParseOptions parseOptions)
{
//
{
if
(
operatorDeclaration
.
ExpressionBody
==
null
)
//
if (operatorDeclaration.ExpressionBody == null)
{
//
{
var
expressionBodyPreference
=
options
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedMethods
).
Value
;
//
var expressionBodyPreference = options.Options.GetOption(CSharpCodeStyleOptions.PreferExpressionBodiedMethods).Value;
if
(
operatorDeclaration
.
Body
.
TryConvertToArrowExpressionBody
(
//
if (operatorDeclaration.Body.TryConvertToArrowExpressionBody(
operatorDeclaration
.
Kind
(),
parseOptions
,
expressionBodyPreference
,
//
operatorDeclaration.Kind(), parseOptions, expressionBodyPreference,
out
var
expressionBody
,
out
var
semicolonToken
))
//
out var expressionBody, out var semicolonToken))
{
//
{
return
operatorDeclaration
.
WithBody
(
null
)
//
return operatorDeclaration.WithBody(null)
.
WithExpressionBody
(
expressionBody
)
//
.WithExpressionBody(expressionBody)
.
WithSemicolonToken
(
semicolonToken
);
//
.WithSemicolonToken(semicolonToken);
}
//
}
}
//
}
return
operatorDeclaration
;
//
return operatorDeclaration;
}
//
}
private
static
SyntaxTokenList
GenerateModifiers
()
private
static
SyntaxTokenList
GenerateModifiers
()
{
{
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
浏览文件 @
e0f1c9ea
...
@@ -33,12 +33,11 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -33,12 +33,11 @@ public static bool CanBeGenerated(IPropertySymbol property)
internal
static
CompilationUnitSyntax
AddPropertyTo
(
internal
static
CompilationUnitSyntax
AddPropertyTo
(
CompilationUnitSyntax
destination
,
CompilationUnitSyntax
destination
,
IPropertySymbol
property
,
IPropertySymbol
property
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
IList
<
bool
>
availableIndices
)
IList
<
bool
>
availableIndices
)
{
{
var
declaration
=
GeneratePropertyOrIndexer
(
var
declaration
=
GeneratePropertyOrIndexer
(
property
,
CodeGenerationDestination
.
CompilationUnit
,
workspace
,
options
,
property
,
CodeGenerationDestination
.
CompilationUnit
,
options
,
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
var
members
=
Insert
(
destination
.
Members
,
declaration
,
options
,
var
members
=
Insert
(
destination
.
Members
,
declaration
,
options
,
...
@@ -49,11 +48,10 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -49,11 +48,10 @@ public static bool CanBeGenerated(IPropertySymbol property)
internal
static
TypeDeclarationSyntax
AddPropertyTo
(
internal
static
TypeDeclarationSyntax
AddPropertyTo
(
TypeDeclarationSyntax
destination
,
TypeDeclarationSyntax
destination
,
IPropertySymbol
property
,
IPropertySymbol
property
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
IList
<
bool
>
availableIndices
)
IList
<
bool
>
availableIndices
)
{
{
var
declaration
=
GeneratePropertyOrIndexer
(
property
,
GetDestination
(
destination
),
workspace
,
var
declaration
=
GeneratePropertyOrIndexer
(
property
,
GetDestination
(
destination
),
options
,
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
options
,
destination
?.
SyntaxTree
.
Options
??
options
.
ParseOptions
);
// Create a clone of the original type with the new method inserted.
// Create a clone of the original type with the new method inserted.
...
@@ -68,7 +66,6 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -68,7 +66,6 @@ public static bool CanBeGenerated(IPropertySymbol property)
public
static
MemberDeclarationSyntax
GeneratePropertyOrIndexer
(
public
static
MemberDeclarationSyntax
GeneratePropertyOrIndexer
(
IPropertySymbol
property
,
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
CodeGenerationDestination
destination
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
...
@@ -79,8 +76,8 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -79,8 +76,8 @@ public static bool CanBeGenerated(IPropertySymbol property)
}
}
var
declaration
=
property
.
IsIndexer
var
declaration
=
property
.
IsIndexer
?
GenerateIndexerDeclaration
(
property
,
destination
,
workspace
,
options
,
parseOptions
)
?
GenerateIndexerDeclaration
(
property
,
destination
,
options
,
parseOptions
)
:
GeneratePropertyDeclaration
(
property
,
destination
,
workspace
,
options
,
parseOptions
);
:
GeneratePropertyDeclaration
(
property
,
destination
,
options
,
parseOptions
);
return
ConditionallyAddDocumentationCommentTo
(
declaration
,
property
,
options
);
return
ConditionallyAddDocumentationCommentTo
(
declaration
,
property
,
options
);
}
}
...
@@ -88,7 +85,6 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -88,7 +85,6 @@ public static bool CanBeGenerated(IPropertySymbol property)
private
static
MemberDeclarationSyntax
GenerateIndexerDeclaration
(
private
static
MemberDeclarationSyntax
GenerateIndexerDeclaration
(
IPropertySymbol
property
,
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
CodeGenerationDestination
destination
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
...
@@ -100,8 +96,8 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -100,8 +96,8 @@ public static bool CanBeGenerated(IPropertySymbol property)
type
:
GenerateTypeSyntax
(
property
),
type
:
GenerateTypeSyntax
(
property
),
explicitInterfaceSpecifier
:
explicitInterfaceSpecifier
,
explicitInterfaceSpecifier
:
explicitInterfaceSpecifier
,
parameterList
:
ParameterGenerator
.
GenerateBracketedParameterList
(
property
.
Parameters
,
explicitInterfaceSpecifier
!=
null
,
options
),
parameterList
:
ParameterGenerator
.
GenerateBracketedParameterList
(
property
.
Parameters
,
explicitInterfaceSpecifier
!=
null
,
options
),
accessorList
:
GenerateAccessorList
(
property
,
destination
,
workspace
,
options
,
parseOptions
));
accessorList
:
GenerateAccessorList
(
property
,
destination
,
options
,
parseOptions
));
declaration
=
UseExpressionBodyIfDesired
(
workspace
,
declaration
,
parseOptions
);
declaration
=
UseExpressionBodyIfDesired
(
options
,
declaration
,
parseOptions
);
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
AddAnnotationsTo
(
property
,
declaration
));
AddAnnotationsTo
(
property
,
declaration
));
...
@@ -109,7 +105,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -109,7 +105,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
private
static
MemberDeclarationSyntax
GeneratePropertyDeclaration
(
private
static
MemberDeclarationSyntax
GeneratePropertyDeclaration
(
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
Workspace
workspace
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
{
{
var
initializer
=
CodeGenerationPropertyInfo
.
GetInitializer
(
property
)
is
ExpressionSyntax
initializerNode
var
initializer
=
CodeGenerationPropertyInfo
.
GetInitializer
(
property
)
is
ExpressionSyntax
initializerNode
?
SyntaxFactory
.
EqualsValueClause
(
initializerNode
)
?
SyntaxFactory
.
EqualsValueClause
(
initializerNode
)
...
@@ -117,7 +113,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -117,7 +113,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
var
explicitInterfaceSpecifier
=
GenerateExplicitInterfaceSpecifier
(
property
.
ExplicitInterfaceImplementations
);
var
explicitInterfaceSpecifier
=
GenerateExplicitInterfaceSpecifier
(
property
.
ExplicitInterfaceImplementations
);
var
accessorList
=
GenerateAccessorList
(
property
,
destination
,
workspace
,
options
,
parseOptions
);
var
accessorList
=
GenerateAccessorList
(
property
,
destination
,
options
,
parseOptions
);
var
propertyDeclaration
=
SyntaxFactory
.
PropertyDeclaration
(
var
propertyDeclaration
=
SyntaxFactory
.
PropertyDeclaration
(
attributeLists
:
AttributeGenerator
.
GenerateAttributeLists
(
property
.
GetAttributes
(),
options
),
attributeLists
:
AttributeGenerator
.
GenerateAttributeLists
(
property
.
GetAttributes
(),
options
),
...
@@ -129,8 +125,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
...
@@ -129,8 +125,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
expressionBody
:
null
,
expressionBody
:
null
,
initializer
:
initializer
);
initializer
:
initializer
);
propertyDeclaration
=
UseExpressionBodyIfDesired
(
propertyDeclaration
=
UseExpressionBodyIfDesired
(
options
,
propertyDeclaration
,
parseOptions
);
workspace
,
propertyDeclaration
,
parseOptions
);
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
return
AddFormatterAndCodeGeneratorAnnotationsTo
(
AddAnnotationsTo
(
property
,
propertyDeclaration
));
AddAnnotationsTo
(
property
,
propertyDeclaration
));
...
@@ -177,15 +172,15 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
...
@@ -177,15 +172,15 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
}
}
private
static
PropertyDeclarationSyntax
UseExpressionBodyIfDesired
(
private
static
PropertyDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
PropertyDeclarationSyntax
declaration
,
ParseOptions
o
ptions
)
CodeGenerationOptions
options
,
PropertyDeclarationSyntax
declaration
,
ParseOptions
parseO
ptions
)
{
{
if
(
declaration
.
ExpressionBody
==
null
)
if
(
declaration
.
ExpressionBody
==
null
)
{
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedProperties
).
Value
;
var
expressionBodyPreference
=
options
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedProperties
).
Value
;
if
(
declaration
.
Initializer
==
null
)
if
(
declaration
.
Initializer
==
null
)
{
{
if
(
TryGetExpressionBody
(
if
(
TryGetExpressionBody
(
declaration
,
o
ptions
,
expressionBodyPreference
,
declaration
,
parseO
ptions
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
out
var
expressionBody
,
out
var
semicolonToken
))
{
{
declaration
=
declaration
.
WithAccessorList
(
null
)
declaration
=
declaration
.
WithAccessorList
(
null
)
...
@@ -199,13 +194,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
...
@@ -199,13 +194,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
}
}
private
static
IndexerDeclarationSyntax
UseExpressionBodyIfDesired
(
private
static
IndexerDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
IndexerDeclarationSyntax
declaration
,
ParseOptions
o
ptions
)
CodeGenerationOptions
options
,
IndexerDeclarationSyntax
declaration
,
ParseOptions
parseO
ptions
)
{
{
if
(
declaration
.
ExpressionBody
==
null
)
if
(
declaration
.
ExpressionBody
==
null
)
{
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedIndexers
).
Value
;
var
expressionBodyPreference
=
options
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedIndexers
).
Value
;
if
(
TryGetExpressionBody
(
if
(
TryGetExpressionBody
(
declaration
,
o
ptions
,
expressionBodyPreference
,
declaration
,
parseO
ptions
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
out
var
expressionBody
,
out
var
semicolonToken
))
{
{
declaration
=
declaration
.
WithAccessorList
(
null
)
declaration
=
declaration
.
WithAccessorList
(
null
)
...
@@ -218,13 +213,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
...
@@ -218,13 +213,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
}
}
private
static
AccessorDeclarationSyntax
UseExpressionBodyIfDesired
(
private
static
AccessorDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
AccessorDeclarationSyntax
declaration
,
ParseOptions
o
ptions
)
CodeGenerationOptions
options
,
AccessorDeclarationSyntax
declaration
,
ParseOptions
parseO
ptions
)
{
{
if
(
declaration
.
ExpressionBody
==
null
)
if
(
declaration
.
ExpressionBody
==
null
)
{
{
var
expressionBodyPreference
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedAccessors
).
Value
;
var
expressionBodyPreference
=
options
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedAccessors
).
Value
;
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
if
(
declaration
.
Body
.
TryConvertToArrowExpressionBody
(
declaration
.
Kind
(),
o
ptions
,
expressionBodyPreference
,
declaration
.
Kind
(),
parseO
ptions
,
expressionBodyPreference
,
out
var
expressionBody
,
out
var
semicolonToken
))
out
var
expressionBody
,
out
var
semicolonToken
))
{
{
declaration
=
declaration
.
WithBody
(
null
)
declaration
=
declaration
.
WithBody
(
null
)
...
@@ -255,13 +250,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
...
@@ -255,13 +250,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
private
static
AccessorListSyntax
GenerateAccessorList
(
private
static
AccessorListSyntax
GenerateAccessorList
(
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
Workspace
workspace
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
{
{
var
setAccessorKind
=
property
.
SetMethod
?.
IsInitOnly
==
true
?
SyntaxKind
.
InitAccessorDeclaration
:
SyntaxKind
.
SetAccessorDeclaration
;
var
setAccessorKind
=
property
.
SetMethod
?.
IsInitOnly
==
true
?
SyntaxKind
.
InitAccessorDeclaration
:
SyntaxKind
.
SetAccessorDeclaration
;
var
accessors
=
new
List
<
AccessorDeclarationSyntax
>
var
accessors
=
new
List
<
AccessorDeclarationSyntax
>
{
{
GenerateAccessorDeclaration
(
property
,
property
.
GetMethod
,
SyntaxKind
.
GetAccessorDeclaration
,
destination
,
workspace
,
options
,
parseOptions
),
GenerateAccessorDeclaration
(
property
,
property
.
GetMethod
,
SyntaxKind
.
GetAccessorDeclaration
,
destination
,
options
,
parseOptions
),
GenerateAccessorDeclaration
(
property
,
property
.
SetMethod
,
setAccessorKind
,
destination
,
workspace
,
options
,
parseOptions
),
GenerateAccessorDeclaration
(
property
,
property
.
SetMethod
,
setAccessorKind
,
destination
,
options
,
parseOptions
),
};
};
return
accessors
[
0
]
==
null
&&
accessors
[
1
]
==
null
return
accessors
[
0
]
==
null
&&
accessors
[
1
]
==
null
...
@@ -274,14 +269,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
...
@@ -274,14 +269,13 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
IMethodSymbol
accessor
,
IMethodSymbol
accessor
,
SyntaxKind
kind
,
SyntaxKind
kind
,
CodeGenerationDestination
destination
,
CodeGenerationDestination
destination
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
var
hasBody
=
options
.
GenerateMethodBodies
&&
HasAccessorBodies
(
property
,
destination
,
accessor
);
var
hasBody
=
options
.
GenerateMethodBodies
&&
HasAccessorBodies
(
property
,
destination
,
accessor
);
return
accessor
==
null
return
accessor
==
null
?
null
?
null
:
GenerateAccessorDeclaration
(
property
,
accessor
,
kind
,
hasBody
,
workspace
,
options
,
parseOptions
);
:
GenerateAccessorDeclaration
(
property
,
accessor
,
kind
,
hasBody
,
options
,
parseOptions
);
}
}
private
static
AccessorDeclarationSyntax
GenerateAccessorDeclaration
(
private
static
AccessorDeclarationSyntax
GenerateAccessorDeclaration
(
...
@@ -289,7 +283,6 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
...
@@ -289,7 +283,6 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
IMethodSymbol
accessor
,
IMethodSymbol
accessor
,
SyntaxKind
kind
,
SyntaxKind
kind
,
bool
hasBody
,
bool
hasBody
,
Workspace
workspace
,
CodeGenerationOptions
options
,
CodeGenerationOptions
options
,
ParseOptions
parseOptions
)
ParseOptions
parseOptions
)
{
{
...
@@ -298,7 +291,7 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
...
@@ -298,7 +291,7 @@ private static TypeSyntax GenerateTypeSyntax(IPropertySymbol property)
.
WithBody
(
hasBody
?
GenerateBlock
(
accessor
)
:
null
)
.
WithBody
(
hasBody
?
GenerateBlock
(
accessor
)
:
null
)
.
WithSemicolonToken
(
hasBody
?
default
:
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
));
.
WithSemicolonToken
(
hasBody
?
default
:
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
));
declaration
=
UseExpressionBodyIfDesired
(
workspace
,
declaration
,
parseOptions
);
declaration
=
UseExpressionBodyIfDesired
(
options
,
declaration
,
parseOptions
);
return
AddAnnotationsTo
(
accessor
,
declaration
);
return
AddAnnotationsTo
(
accessor
,
declaration
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录