Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
38358994
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,发现更多精彩内容 >>
提交
38358994
编写于
2月 28, 2018
作者:
M
Martin Strecker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix for insert position after optional parameters.
上级
283ebc74
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
11 deletion
+16
-11
src/EditorFeatures/CSharpTest/AddParameter/AddParameterTests.cs
...itorFeatures/CSharpTest/AddParameter/AddParameterTests.cs
+1
-4
src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs
...table/AddParameter/AbstractAddParameterCodeFixProvider.cs
+15
-7
未找到文件。
src/EditorFeatures/CSharpTest/AddParameter/AddParameterTests.cs
浏览文件 @
38358994
...
...
@@ -2001,8 +2001,6 @@ void Test()
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddParameter
)]
public
async
Task
TestInvocation_InvocationStyles_Positional_WithOptionalParam
()
{
// The fix places new parameter after optional parameters (which is not allowed)
// I don't see what we can do about it without also changing the call site.
// error CS1501: No overload for method 'M' takes 2 arguments
var
code
=
@"
...
...
@@ -2014,12 +2012,11 @@ void Test()
[|M|](1, 2);
}
}"
;
// error CS1737: Optional parameters must appear after all required parameters
var
fix0
=
@"
class C
{
void M(int i = 1, int v) { }
void M(int i = 1, int v
= 0
) { }
void Test()
{
M(1, 2);
...
...
src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs
浏览文件 @
38358994
...
...
@@ -326,10 +326,21 @@ private static string GetCodeFixTitle(string resourceString, IMethodSymbol metho
foreach
(
var
methodDeclaration
in
documentLookup
)
{
var
methodNode
=
syntaxRoot
.
FindNode
(
methodDeclaration
.
Locations
[
0
].
SourceSpan
);
var
existingParameters
=
generator
.
GetParameters
(
methodNode
);
var
insertionIndex
=
isNamedArgument
?
existingParameters
.
Count
:
argumentList
.
IndexOf
(
argument
);
// if the preceding parameter is optional, the new parameter must also be optional
// see also BC30202 and CS1737
var
parameterMustBeOptional
=
insertionIndex
>
0
&&
syntaxFacts
.
GetDefaultOfParameter
(
existingParameters
[
insertionIndex
-
1
])
!=
null
;
var
parameterSymbol
=
CreateParameterSymbol
(
methodDeclaration
,
argumentType
,
refKind
,
argumentNameSuggestion
);
methodDeclaration
,
argumentType
,
refKind
,
parameterMustBeOptional
,
argumentNameSuggestion
);
var
parameterDeclaration
=
generator
.
ParameterDeclaration
(
parameterSymbol
)
var
argumentInitializer
=
parameterMustBeOptional
?
generator
.
DefaultExpression
(
argumentType
)
:
null
;
var
parameterDeclaration
=
generator
.
ParameterDeclaration
(
parameterSymbol
,
argumentInitializer
)
.
WithAdditionalAnnotations
(
Formatter
.
Annotation
);
if
(
anySymbolReferencesNotInSource
&&
methodDeclaration
==
method
)
{
...
...
@@ -337,10 +348,6 @@ private static string GetCodeFixTitle(string resourceString, IMethodSymbol metho
ConflictAnnotation
.
Create
(
FeaturesResources
.
Related_method_signatures_found_in_metadata_will_not_be_updated
));
}
var
existingParameters
=
generator
.
GetParameters
(
methodNode
);
var
insertionIndex
=
isNamedArgument
?
existingParameters
.
Count
:
argumentList
.
IndexOf
(
argument
);
if
(
method
.
MethodKind
==
MethodKind
.
ReducedExtension
)
{
...
...
@@ -409,11 +416,12 @@ private static async Task<(ITypeSymbol, RefKind)> GetArgumentTypeAndRefKindAsync
IMethodSymbol
method
,
ITypeSymbol
parameterType
,
RefKind
refKind
,
bool
isOptional
,
string
argumentNameSuggestion
)
{
var
uniqueName
=
NameGenerator
.
EnsureUniqueness
(
argumentNameSuggestion
,
method
.
Parameters
.
Select
(
p
=>
p
.
Name
));
var
newParameterSymbol
=
CodeGenerationSymbolFactory
.
CreateParameterSymbol
(
attributes
:
default
,
refKind
:
refKind
,
isParams
:
false
,
type
:
parameterType
,
name
:
uniqueName
);
attributes
:
default
,
refKind
:
refKind
,
is
Optional
:
isOptional
,
is
Params
:
false
,
type
:
parameterType
,
name
:
uniqueName
);
return
newParameterSymbol
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录