Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
25f29601
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,发现更多精彩内容 >>
提交
25f29601
编写于
10月 09, 2016
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for generating accessors with expression bodies.
上级
83242854
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
53 addition
and
24 deletion
+53
-24
src/Workspaces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
...ces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
+1
-1
src/Workspaces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
...paces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
+3
-2
src/Workspaces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
...paces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
+49
-21
未找到文件。
src/Workspaces/CSharp/Portable/CodeGeneration/ConversionGenerator.cs
浏览文件 @
25f29601
...
...
@@ -79,7 +79,7 @@ internal static class ConversionGenerator
{
if
(
declaration
.
ExpressionBody
==
null
)
{
var
preferExpressionBody
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodied
Method
s
).
Value
;
var
preferExpressionBody
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodied
Operator
s
).
Value
;
if
(
preferExpressionBody
)
{
var
expressionBody
=
CodeGenerationHelpers
.
TryConvertToExpressionBody
(
declaration
.
Body
);
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/OperatorGenerator.cs
浏览文件 @
25f29601
...
...
@@ -48,11 +48,12 @@ internal static class OperatorGenerator
ConditionallyAddDocumentationCommentTo
(
declaration
,
method
,
options
));
}
private
static
OperatorDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
OperatorDeclarationSyntax
declaration
)
private
static
OperatorDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
OperatorDeclarationSyntax
declaration
)
{
if
(
declaration
.
ExpressionBody
==
null
)
{
var
preferExpressionBody
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodied
Method
s
).
Value
;
var
preferExpressionBody
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodied
Operator
s
).
Value
;
if
(
preferExpressionBody
)
{
var
expressionBody
=
CodeGenerationHelpers
.
TryConvertToExpressionBody
(
declaration
.
Body
);
...
...
src/Workspaces/CSharp/Portable/CodeGeneration/PropertyGenerator.cs
浏览文件 @
25f29601
...
...
@@ -95,7 +95,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
type
:
property
.
Type
.
GenerateTypeSyntax
(),
explicitInterfaceSpecifier
:
explicitInterfaceSpecifier
,
parameterList
:
ParameterGenerator
.
GenerateBracketedParameterList
(
property
.
Parameters
,
explicitInterfaceSpecifier
!=
null
,
options
),
accessorList
:
GenerateAccessorList
(
property
,
destination
,
options
));
accessorList
:
GenerateAccessorList
(
property
,
destination
,
workspace
,
options
));
declaration
=
UseExpressionBodyIfDesired
(
workspace
,
declaration
);
return
AddCleanupAnnotationsTo
(
...
...
@@ -114,7 +114,7 @@ public static bool CanBeGenerated(IPropertySymbol property)
var
explicitInterfaceSpecifier
=
GenerateExplicitInterfaceSpecifier
(
property
.
ExplicitInterfaceImplementations
);
var
accessorList
=
GenerateAccessorList
(
property
,
destination
,
options
);
var
accessorList
=
GenerateAccessorList
(
property
,
destination
,
workspace
,
options
);
var
propertyDeclaration
=
SyntaxFactory
.
PropertyDeclaration
(
attributeLists
:
AttributeGenerator
.
GenerateAttributeLists
(
property
.
GetAttributes
(),
options
),
...
...
@@ -133,6 +133,20 @@ public static bool CanBeGenerated(IPropertySymbol property)
AddAnnotationsTo
(
property
,
propertyDeclaration
));
}
private
static
ArrowExpressionClauseSyntax
TryGetExpressionBody
(
AccessorListSyntax
accessorList
)
{
if
(
accessorList
.
Accessors
.
Count
==
1
)
{
var
accessor
=
accessorList
.
Accessors
[
0
];
if
(
accessor
.
IsKind
(
SyntaxKind
.
GetAccessorDeclaration
))
{
return
TryGetExpressionBody
(
accessor
);
}
}
return
null
;
}
private
static
PropertyDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
PropertyDeclarationSyntax
declaration
)
{
...
...
@@ -157,32 +171,39 @@ public static bool CanBeGenerated(IPropertySymbol property)
return
declaration
;
}
private
static
ArrowExpressionClauseSyntax
TryGetExpressionBody
(
AccessorListSyntax
accessorList
)
private
static
IndexerDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
IndexerDeclarationSyntax
declaration
)
{
if
(
accessorList
.
Accessors
.
Count
==
1
)
if
(
declaration
.
ExpressionBody
==
null
)
{
var
accessor
=
accessorList
.
Accessors
[
0
]
;
if
(
accessor
.
IsKind
(
SyntaxKind
.
GetAccessorDeclaration
)
)
var
preferExpressionBody
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodiedIndexers
).
Value
;
if
(
preferExpressionBody
)
{
return
TryGetExpressionBody
(
accessor
);
var
expressionBody
=
TryGetExpressionBody
(
declaration
.
AccessorList
);
if
(
expressionBody
!=
null
)
{
declaration
=
declaration
.
WithAccessorList
(
null
)
.
WithExpressionBody
(
expressionBody
)
.
WithSemicolonToken
(
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
));
}
}
}
return
null
;
return
declaration
;
}
private
static
Indexe
rDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
Indexe
rDeclarationSyntax
declaration
)
private
static
Accesso
rDeclarationSyntax
UseExpressionBodyIfDesired
(
Workspace
workspace
,
Accesso
rDeclarationSyntax
declaration
)
{
if
(
declaration
.
ExpressionBody
==
null
)
{
var
preferExpressionBody
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodied
Propertie
s
).
Value
;
var
preferExpressionBody
=
workspace
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferExpressionBodied
Accessor
s
).
Value
;
if
(
preferExpressionBody
)
{
var
expressionBody
=
TryGetExpressionBody
(
declaration
.
AccessorList
);
var
expressionBody
=
CodeGenerationHelpers
.
TryConvertToExpressionBody
(
declaration
.
Body
);
if
(
expressionBody
!=
null
)
{
declaration
=
declaration
.
With
AccessorList
(
null
)
declaration
=
declaration
.
With
Body
(
null
)
.
WithExpressionBody
(
expressionBody
)
.
WithSemicolonToken
(
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
));
}
...
...
@@ -202,12 +223,13 @@ private static ArrowExpressionClauseSyntax TryGetExpressionBody(AccessorDeclarat
}
private
static
AccessorListSyntax
GenerateAccessorList
(
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
CodeGenerationOptions
options
)
IPropertySymbol
property
,
CodeGenerationDestination
destination
,
Workspace
workspace
,
CodeGenerationOptions
options
)
{
var
accessors
=
new
List
<
AccessorDeclarationSyntax
>
{
GenerateAccessorDeclaration
(
property
,
property
.
GetMethod
,
SyntaxKind
.
GetAccessorDeclaration
,
destination
,
options
),
GenerateAccessorDeclaration
(
property
,
property
.
SetMethod
,
SyntaxKind
.
SetAccessorDeclaration
,
destination
,
options
),
GenerateAccessorDeclaration
(
property
,
property
.
GetMethod
,
SyntaxKind
.
GetAccessorDeclaration
,
destination
,
workspace
,
options
),
GenerateAccessorDeclaration
(
property
,
property
.
SetMethod
,
SyntaxKind
.
SetAccessorDeclaration
,
destination
,
workspace
,
options
),
};
return
accessors
[
0
]
==
null
&&
accessors
[
1
]
==
null
...
...
@@ -220,12 +242,13 @@ private static ArrowExpressionClauseSyntax TryGetExpressionBody(AccessorDeclarat
IMethodSymbol
accessor
,
SyntaxKind
kind
,
CodeGenerationDestination
destination
,
Workspace
workspace
,
CodeGenerationOptions
options
)
{
var
hasBody
=
options
.
GenerateMethodBodies
&&
HasAccessorBodies
(
property
,
destination
,
accessor
);
return
accessor
==
null
?
null
:
GenerateAccessorDeclaration
(
property
,
accessor
,
kind
,
hasBody
,
options
);
:
GenerateAccessorDeclaration
(
property
,
accessor
,
kind
,
hasBody
,
workspace
,
options
);
}
private
static
AccessorDeclarationSyntax
GenerateAccessorDeclaration
(
...
...
@@ -233,12 +256,17 @@ private static ArrowExpressionClauseSyntax TryGetExpressionBody(AccessorDeclarat
IMethodSymbol
accessor
,
SyntaxKind
kind
,
bool
hasBody
,
Workspace
workspace
,
CodeGenerationOptions
options
)
{
return
AddAnnotationsTo
(
accessor
,
SyntaxFactory
.
AccessorDeclaration
(
kind
)
.
WithModifiers
(
GenerateAccessorModifiers
(
property
,
accessor
,
options
))
.
WithBody
(
hasBody
?
GenerateBlock
(
accessor
)
:
null
)
.
WithSemicolonToken
(
hasBody
?
default
(
SyntaxToken
)
:
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
)));
var
declaration
=
SyntaxFactory
.
AccessorDeclaration
(
kind
)
.
WithModifiers
(
GenerateAccessorModifiers
(
property
,
accessor
,
options
))
.
WithBody
(
hasBody
?
GenerateBlock
(
accessor
)
:
null
)
.
WithSemicolonToken
(
hasBody
?
default
(
SyntaxToken
)
:
SyntaxFactory
.
Token
(
SyntaxKind
.
SemicolonToken
));
declaration
=
UseExpressionBodyIfDesired
(
workspace
,
declaration
);
return
AddAnnotationsTo
(
accessor
,
declaration
);
}
private
static
BlockSyntax
GenerateBlock
(
IMethodSymbol
accessor
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录