Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
e1f15cd0
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,发现更多精彩内容 >>
提交
e1f15cd0
编写于
4月 24, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use tuple
上级
45bb7f64
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
10 addition
and
12 deletion
+10
-12
src/Features/CSharp/Portable/EncapsulateField/CSharpEncapsulateFieldService.cs
...ortable/EncapsulateField/CSharpEncapsulateFieldService.cs
+5
-5
src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs
...table/EncapsulateField/AbstractEncapsulateFieldService.cs
+2
-4
src/Features/VisualBasic/Portable/EncapsulateField/VisualBasicEncapsulateFieldService.vb
...le/EncapsulateField/VisualBasicEncapsulateFieldService.vb
+3
-3
未找到文件。
src/Features/CSharp/Portable/EncapsulateField/CSharpEncapsulateFieldService.cs
浏览文件 @
e1f15cd0
...
...
@@ -146,13 +146,13 @@ protected override async Task<IEnumerable<IFieldSymbol>> GetFieldsAsync(Document
private
bool
CanEncapsulate
(
FieldDeclarationSyntax
field
)
=>
field
.
Parent
is
TypeDeclarationSyntax
;
protected
override
Tuple
<
string
,
string
>
GeneratePropertyAndField
Names
(
IFieldSymbol
field
)
protected
override
(
string
fieldName
,
string
propertyName
)
GenerateFieldAndProperty
Names
(
IFieldSymbol
field
)
{
// Special case: if the field is "new", we will preserve its original name and the new keyword.
if
(
field
.
DeclaredAccessibility
==
Accessibility
.
Private
||
IsNew
(
field
))
{
// Create some capitalized version of the field name for the property
return
Tuple
.
Create
(
field
.
Name
,
MakeUnique
(
GeneratePropertyName
(
field
.
Name
),
field
.
ContainingType
));
return
(
field
.
Name
,
MakeUnique
(
GeneratePropertyName
(
field
.
Name
),
field
.
ContainingType
));
}
else
{
...
...
@@ -162,7 +162,7 @@ private bool CanEncapsulate(FieldDeclarationSyntax field)
if
(
newPropertyName
==
field
.
Name
)
{
// If we wind up with the field's old name, give the field the unique version of its current name.
return
Tuple
.
Create
(
MakeUnique
(
GenerateFieldName
(
field
.
Name
),
field
.
ContainingType
),
newPropertyName
);
return
(
MakeUnique
(
GenerateFieldName
(
field
.
Name
),
field
.
ContainingType
),
newPropertyName
);
}
// Otherwise, ensure the property's name is unique.
...
...
@@ -172,11 +172,11 @@ private bool CanEncapsulate(FieldDeclarationSyntax field)
// If converting the new property's name into a field name results in the old field name, we're done.
if
(
newFieldName
==
field
.
Name
)
{
return
Tuple
.
Create
(
newFieldName
,
newPropertyName
);
return
(
newFieldName
,
newPropertyName
);
}
// Otherwise, ensure the new field name is unique.
return
Tuple
.
Create
(
MakeUnique
(
newFieldName
,
field
.
ContainingType
),
newPropertyName
);
return
(
MakeUnique
(
newFieldName
,
field
.
ContainingType
),
newPropertyName
);
}
}
...
...
src/Features/Core/Portable/EncapsulateField/AbstractEncapsulateFieldService.cs
浏览文件 @
e1f15cd0
...
...
@@ -150,9 +150,7 @@ private async Task<Result> EncapsulateFieldResultAsync(Document document, TextSp
private
async
Task
<
Result
>
EncapsulateFieldAsync
(
IFieldSymbol
field
,
Document
document
,
bool
updateReferences
,
CancellationToken
cancellationToken
)
{
var
originalField
=
field
;
var
finalNames
=
GeneratePropertyAndFieldNames
(
field
);
var
finalFieldName
=
finalNames
.
Item1
;
var
generatedPropertyName
=
finalNames
.
Item2
;
var
(
finalFieldName
,
generatedPropertyName
)
=
GenerateFieldAndPropertyNames
(
field
);
// Annotate the field declarations so we can find it after rename.
var
fieldDeclaration
=
field
.
DeclaringSyntaxReferences
.
First
();
...
...
@@ -352,7 +350,7 @@ protected async Task<Solution> AddPropertyAsync(Document document, Solution dest
Formatter
.
Annotation
.
AddAnnotationToSymbol
(
propertySymbol
));
}
protected
abstract
Tuple
<
string
,
string
>
GeneratePropertyAndField
Names
(
IFieldSymbol
field
);
protected
abstract
(
string
fieldName
,
string
propertyName
)
GenerateFieldAndProperty
Names
(
IFieldSymbol
field
);
protected
Accessibility
ComputeAccessibility
(
Accessibility
accessibility
,
ITypeSymbol
type
)
{
...
...
src/Features/VisualBasic/Portable/EncapsulateField/VisualBasicEncapsulateFieldService.vb
浏览文件 @
e1f15cd0
...
...
@@ -100,19 +100,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.EncapsulateField
End
If
End
Function
Protected
Overrides
Function
Generate
PropertyAndFieldNames
(
field
As
IFieldSymbol
)
As
Tuple
(
Of
String
,
String
)
Protected
Overrides
Function
Generate
FieldAndPropertyNames
(
field
As
IFieldSymbol
)
As
(
fieldName
As
String
,
propertyName
As
String
)
' If the field is marked shadows, it will keep its name.
If
field
.
DeclaredAccessibility
=
Accessibility
.
Private
OrElse
IsShadows
(
field
)
Then
Dim
propertyName
=
GeneratePropertyName
(
field
.
Name
)
propertyName
=
MakeUnique
(
propertyName
,
field
)
Return
Tuple
.
Create
(
field
.
Name
,
propertyName
)
Return
(
field
.
Name
,
propertyName
)
Else
Dim
propertyName
=
GeneratePropertyName
(
field
.
Name
)
Dim
containingTypeMemberNames
=
field
.
ContainingType
.
GetAccessibleMembersInThisAndBaseTypes
(
Of
ISymbol
)(
field
.
ContainingType
).
Select
(
Function
(
s
)
s
.
Name
)
propertyName
=
NameGenerator
.
GenerateUniqueName
(
propertyName
,
containingTypeMemberNames
.
Where
(
Function
(
m
)
m
<>
field
.
Name
).
ToSet
(),
StringComparer
.
OrdinalIgnoreCase
)
Dim
newFieldName
=
MakeUnique
(
"_"
+
Char
.
ToLower
(
propertyName
(
0
))
+
propertyName
.
Substring
(
1
),
field
)
Return
Tuple
.
Create
(
newFieldName
,
propertyName
)
Return
(
newFieldName
,
propertyName
)
End
If
End
Function
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录