Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
7a80c18a
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,发现更多精彩内容 >>
提交
7a80c18a
编写于
6月 02, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Simplify more.
上级
b5c63ed3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
42 addition
and
47 deletion
+42
-47
src/EditorFeatures/CSharpTest/GenerateConstructor/GenerateConstructorTests.cs
...SharpTest/GenerateConstructor/GenerateConstructorTests.cs
+1
-1
src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.State.cs
...teConstructor/AbstractGenerateConstructorService.State.cs
+41
-46
未找到文件。
src/EditorFeatures/CSharpTest/GenerateConstructor/GenerateConstructorTests.cs
浏览文件 @
7a80c18a
...
...
@@ -715,7 +715,7 @@ class D : B
public D(int x)
{
this.x
= x;
X
= x;
}
}"
);
}
...
...
src/Features/Core/Portable/GenerateMember/GenerateConstructor/AbstractGenerateConstructorService.State.cs
浏览文件 @
7a80c18a
...
...
@@ -382,11 +382,7 @@ private static bool IsValidAttributeParameterType(ITypeSymbol type)
if
(!
TryFindMatchingMember
(
ref
parameterName
,
parameterType
,
argument
,
attributeArgument
,
parameterToExistingMemberMap
,
parameterToNewFieldMap
,
parameterToNewPropertyMap
,
caseSensitive
:
true
,
cancellationToken
)
&&
!
TryFindMatchingMember
(
ref
parameterName
,
parameterType
,
argument
,
attributeArgument
,
parameterToExistingMemberMap
,
parameterToNewFieldMap
,
parameterToNewPropertyMap
,
caseSensitive
:
false
,
cancellationToken
))
cancellationToken
))
{
// If no matching field was found, use the fieldNamingRule to create suitable name
var
bestNameForParameter
=
parameterName
.
BestNameForParameter
;
...
...
@@ -417,7 +413,6 @@ private static bool IsValidAttributeParameterType(ITypeSymbol type)
ImmutableDictionary
<
string
,
ISymbol
>.
Builder
parameterToExistingMemberMap
,
ImmutableDictionary
<
string
,
string
>.
Builder
parameterToNewFieldMap
,
ImmutableDictionary
<
string
,
string
>.
Builder
parameterToNewPropertyMap
,
bool
caseSensitive
,
CancellationToken
cancellationToken
)
{
var
expectedFieldName
=
_fieldNamingRule
.
NamingStyle
.
MakeCompliant
(
parameterName
.
NameBasedOnArgument
).
First
();
...
...
@@ -429,61 +424,61 @@ private static bool IsValidAttributeParameterType(ITypeSymbol type)
// Otherwise, we'll need to choose a different name for this member so that it
// doesn't conflict with something already in the type. First check the current type
// for a matching field. If so, defer to it.
var
comparison
=
caseSensitive
?
StringComparison
.
Ordinal
:
StringComparison
.
OrdinalIgnoreCase
;
var
unavailableMemberNames
=
GetUnavailableMemberNames
().
ToImmutableArray
();
foreach
(
var
type
in
TypeToGenerateIn
.
GetBaseTypesAndThis
())
{
var
ignoreAccessibility
=
type
.
Equals
(
TypeToGenerateIn
);
var
symbol
=
type
.
GetMembers
().
FirstOrDefault
(
s
=>
s
.
Name
.
Equals
(
expectedFieldName
,
comparison
));
var
symbol
=
type
.
GetMembers
().
FirstOrDefault
(
s
=>
s
.
Name
.
Equals
(
expectedFieldName
,
StringComparison
.
Ordinal
))
??
type
.
GetMembers
().
FirstOrDefault
(
s
=>
s
.
Name
.
Equals
(
expectedFieldName
,
StringComparison
.
OrdinalIgnoreCase
));
if
(
symbol
==
null
)
continue
;
if
(
symbol
!=
null
)
if
(
ignoreAccessibility
||
IsSymbolAccessible
(
symbol
,
_document
)
)
{
if
(
ignoreAccessibility
||
IsSymbolAccessible
(
symbol
,
_document
))
if
(
IsViableFieldOrProperty
(
parameterType
,
symbol
))
{
if
(
IsViableFieldOrProperty
(
parameterType
,
symbol
))
// Ok! We can just the existing field.
parameterToExistingMemberMap
[
parameterName
.
BestNameForParameter
]
=
symbol
;
}
else
{
// Uh-oh. Now we have a problem. We can't assign this parameter to
// this field. So we need to create a new field. Find a name not in
// use so we can assign to that.
var
baseName
=
attributeArgument
!=
null
?
_service
.
GenerateNameForArgument
(
_document
.
SemanticModel
,
attributeArgument
,
cancellationToken
)
:
_service
.
GenerateNameForArgument
(
_document
.
SemanticModel
,
argument
,
cancellationToken
);
var
baseFieldWithNamingStyle
=
_fieldNamingRule
.
NamingStyle
.
MakeCompliant
(
baseName
).
First
();
var
basePropertyWithNamingStyle
=
_propertyNamingRule
.
NamingStyle
.
MakeCompliant
(
baseName
).
First
();
var
newFieldName
=
NameGenerator
.
EnsureUniqueness
(
baseFieldWithNamingStyle
,
unavailableMemberNames
.
Concat
(
parameterToNewFieldMap
.
Values
));
var
newPropertyName
=
NameGenerator
.
EnsureUniqueness
(
basePropertyWithNamingStyle
,
unavailableMemberNames
.
Concat
(
parameterToNewPropertyMap
.
Values
));
if
(
isFixed
)
{
// Ok! We can just the existing field.
parameterToExistingMemberMap
[
parameterName
.
BestNameForParameter
]
=
symbol
;
// Can't change the parameter name, so map the existing parameter
// name to the new field name.
parameterToNewFieldMap
[
parameterName
.
NameBasedOnArgument
]
=
newFieldName
;
parameterToNewPropertyMap
[
parameterName
.
NameBasedOnArgument
]
=
newPropertyName
;
}
else
{
// Uh-oh. Now we have a problem. We can't assign this parameter to
// this field. So we need to create a new field. Find a name not in
// use so we can assign to that.
var
baseName
=
attributeArgument
!=
null
?
_service
.
GenerateNameForArgument
(
_document
.
SemanticModel
,
attributeArgument
,
cancellationToken
)
:
_service
.
GenerateNameForArgument
(
_document
.
SemanticModel
,
argument
,
cancellationToken
);
var
baseFieldWithNamingStyle
=
_fieldNamingRule
.
NamingStyle
.
MakeCompliant
(
baseName
).
First
();
var
basePropertyWithNamingStyle
=
_propertyNamingRule
.
NamingStyle
.
MakeCompliant
(
baseName
).
First
();
var
newFieldName
=
NameGenerator
.
EnsureUniqueness
(
baseFieldWithNamingStyle
,
unavailableMemberNames
.
Concat
(
parameterToNewFieldMap
.
Values
));
var
newPropertyName
=
NameGenerator
.
EnsureUniqueness
(
basePropertyWithNamingStyle
,
unavailableMemberNames
.
Concat
(
parameterToNewPropertyMap
.
Values
));
if
(
isFixed
)
{
// Can't change the parameter name, so map the existing parameter
// name to the new field name.
parameterToNewFieldMap
[
parameterName
.
NameBasedOnArgument
]
=
newFieldName
;
parameterToNewPropertyMap
[
parameterName
.
NameBasedOnArgument
]
=
newPropertyName
;
}
else
{
// Can change the parameter name, so do so.
// But first remove any prefix added due to field naming styles
var
fieldNameMinusPrefix
=
newFieldName
.
Substring
(
_fieldNamingRule
.
NamingStyle
.
Prefix
.
Length
);
var
newParameterName
=
new
ParameterName
(
fieldNameMinusPrefix
,
isFixed
:
false
,
_parameterNamingRule
);
parameterName
=
newParameterName
;
parameterToNewFieldMap
[
newParameterName
.
BestNameForParameter
]
=
newFieldName
;
parameterToNewPropertyMap
[
newParameterName
.
BestNameForParameter
]
=
newPropertyName
;
}
// Can change the parameter name, so do so.
// But first remove any prefix added due to field naming styles
var
fieldNameMinusPrefix
=
newFieldName
.
Substring
(
_fieldNamingRule
.
NamingStyle
.
Prefix
.
Length
);
var
newParameterName
=
new
ParameterName
(
fieldNameMinusPrefix
,
isFixed
:
false
,
_parameterNamingRule
);
parameterName
=
newParameterName
;
parameterToNewFieldMap
[
newParameterName
.
BestNameForParameter
]
=
newFieldName
;
parameterToNewPropertyMap
[
newParameterName
.
BestNameForParameter
]
=
newPropertyName
;
}
return
true
;
}
return
true
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录