Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
d300c807
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,发现更多精彩内容 >>
提交
d300c807
编写于
10月 05, 2017
作者:
M
Martin Strecker
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add support for partial methods
上级
6dfd11ef
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
27 deletion
+41
-27
src/EditorFeatures/CSharpTest/AddParameter/AddParameterTests.cs
...itorFeatures/CSharpTest/AddParameter/AddParameterTests.cs
+1
-2
src/Features/CSharp/Portable/GenerateConstructor/GenerateConstructorCodeFixProvider.cs
...GenerateConstructor/GenerateConstructorCodeFixProvider.cs
+2
-2
src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs
...table/AddParameter/AbstractAddParameterCodeFixProvider.cs
+38
-23
未找到文件。
src/EditorFeatures/CSharpTest/AddParameter/AddParameterTests.cs
浏览文件 @
d300c807
...
...
@@ -1378,7 +1378,6 @@ void M2()
[
WorkItem
(
21446
,
"https://github.com/dotnet/roslyn/issues/21446"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsAddParameter
)]
[
Trait
(
"TODO"
,
"Fix all partial definitions"
)]
public
async
Task
TestInvocationPartialClasses
()
{
var
code
=
...
...
@@ -1427,7 +1426,7 @@ namespace N1
{
partial class C1
{
partial void PartialM() { }
partial void PartialM(
int v
) { }
void M1()
{
PartialM(1);
...
...
src/Features/CSharp/Portable/GenerateConstructor/GenerateConstructorCodeFixProvider.cs
浏览文件 @
d300c807
...
...
@@ -23,8 +23,8 @@ internal static class GenerateConstructorDiagnosticIds
public
const
string
CS1660
=
nameof
(
CS1660
);
// CS1660: Cannot convert lambda expression to type 'string[]' because it is not a delegate type
public
const
string
CS7036
=
nameof
(
CS7036
);
// CS7036: There is no argument given that corresponds to the required formal parameter 'v' of 'C.C(int)'
public
static
readonly
ImmutableArray
<
string
>
AllDiagnosticIds
=
ImmutableArray
.
Create
(
CS0122
,
CS1729
,
CS1739
,
CS1503
,
CS7036
);
public
static
readonly
ImmutableArray
<
string
>
AllDiagnosticIds
=
ImmutableArray
.
Create
(
CS0122
,
CS1729
,
CS1739
,
CS1503
,
CS
1660
,
CS
7036
);
public
static
readonly
ImmutableArray
<
string
>
TooManyArgumentsDiagnosticIds
=
ImmutableArray
.
Create
(
CS1729
);
...
...
src/Features/Core/Portable/AddParameter/AbstractAddParameterCodeFixProvider.cs
浏览文件 @
d300c807
...
...
@@ -252,7 +252,7 @@ private TArgumentSyntax GetArgumentInsertPositionForMethodCandidate(SemanticMode
private
int
NonParamsParameterCount
(
IMethodSymbol
method
)
=>
method
.
IsParams
()
?
method
.
Parameters
.
Length
-
1
:
method
.
Parameters
.
Length
;
private
async
Task
<
Document
>
FixAsync
(
private
async
Task
<
Solution
>
FixAsync
(
Document
invocationDocument
,
IMethodSymbol
method
,
TArgumentSyntax
argument
,
...
...
@@ -260,28 +260,43 @@ private int NonParamsParameterCount(IMethodSymbol method)
TTypeSyntax
newTypeArgument
,
CancellationToken
cancellationToken
)
{
var
methodDeclaration
=
await
method
.
DeclaringSyntaxReferences
[
0
].
GetSyntaxAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
methodDeclarationRoot
=
methodDeclaration
.
SyntaxTree
.
GetRoot
(
cancellationToken
);
var
methodDocument
=
invocationDocument
.
Project
.
Solution
.
GetDocument
(
methodDeclaration
.
SyntaxTree
);
var
syntaxFacts
=
methodDocument
.
GetLanguageService
<
ISyntaxFactsService
>();
var
editor
=
new
SyntaxEditor
(
methodDeclarationRoot
,
methodDocument
.
Project
.
Solution
.
Workspace
);
var
parameterDeclaration
=
default
(
SyntaxNode
);
var
insertionIndex
=
default
(
int
);
var
newTypeParameter
=
newTypeArgument
==
null
?
null
:
CreateTypeParameterSymbol
(
method
);
if
(
argument
!=
null
)
{
(
parameterDeclaration
,
insertionIndex
)
=
await
CreateParameterDeclarationAsync
(
editor
,
invocationDocument
,
method
,
methodDeclaration
,
argumentList
,
argument
,
newTypeArgument
,
newTypeParameter
,
cancellationToken
).
ConfigureAwait
(
false
);
}
var
newSolution
=
invocationDocument
.
Project
.
Solution
;
//method.DeclaringSyntaxReferences does no longer return the two locations for partial methods so this is no longer true:
//https://stackoverflow.com/a/38294041
//Therefore we need this ugly hack:
var
methodSymbolReferences
=
Enumerable
.
Repeat
(
method
,
1
)
.
Union
(
Enumerable
.
Repeat
(
method
.
PartialDefinitionPart
,
1
)
.
Union
(
Enumerable
.
Repeat
(
method
.
PartialImplementationPart
,
1
)))
.
Where
(
methodSymbol
=>
methodSymbol
!=
null
)
.
Distinct
().
ToImmutableArray
();
foreach
(
var
methodSymbol
in
methodSymbolReferences
)
{
var
methodDeclaration
=
await
methodSymbol
.
DeclaringSyntaxReferences
[
0
].
GetSyntaxAsync
(
cancellationToken
).
ConfigureAwait
(
false
);
var
methodDeclarationRoot
=
methodDeclaration
.
SyntaxTree
.
GetRoot
(
cancellationToken
);
var
methodDocument
=
invocationDocument
.
Project
.
Solution
.
GetDocument
(
methodDeclaration
.
SyntaxTree
);
var
syntaxFacts
=
methodDocument
.
GetLanguageService
<
ISyntaxFactsService
>();
var
editor
=
new
SyntaxEditor
(
methodDeclarationRoot
,
methodDocument
.
Project
.
Solution
.
Workspace
);
var
parameterDeclaration
=
default
(
SyntaxNode
);
var
insertionIndex
=
default
(
int
);
var
newTypeParameter
=
newTypeArgument
==
null
?
null
:
CreateTypeParameterSymbol
(
method
);
if
(
argument
!=
null
)
{
(
parameterDeclaration
,
insertionIndex
)
=
await
CreateParameterDeclarationAsync
(
editor
,
invocationDocument
,
method
,
methodDeclaration
,
argumentList
,
argument
,
newTypeArgument
,
newTypeParameter
,
cancellationToken
).
ConfigureAwait
(
false
);
}
AddParameter
(
syntaxFacts
,
editor
,
method
,
methodDeclaration
,
argument
,
insertionIndex
,
parameterDeclaration
,
newTypeParameter
,
cancellationToken
);
AddParameter
(
syntaxFacts
,
editor
,
method
,
methodDeclaration
,
argument
,
insertionIndex
,
parameterDeclaration
,
newTypeParameter
,
cancellationToken
);
var
newRoot
=
editor
.
GetChangedRoot
();
var
newDocument
=
methodDocument
.
WithSyntaxRoot
(
newRoot
);
var
newRoot
=
editor
.
GetChangedRoot
();
newSolution
=
newSolution
.
WithDocumentSyntaxRoot
(
methodDocument
.
Id
,
newRoot
);
}
return
new
Document
;
return
new
Solution
;
}
private
async
Task
<(
SyntaxNode
parameterDeclaration
,
int
insertionIndex
)>
CreateParameterDeclarationAsync
(
...
...
@@ -676,12 +691,12 @@ private static ImmutableArray<ITypeParameterSymbol> GetTypeParameterOfClassOrMet
return
false
;
}
private
class
MyCodeAction
:
CodeAction
.
Document
ChangeAction
private
class
MyCodeAction
:
CodeAction
.
Solution
ChangeAction
{
public
MyCodeAction
(
string
title
,
Func
<
CancellationToken
,
Task
<
Document
>>
createChangedDocument
)
:
base
(
title
,
createChanged
Document
)
Func
<
CancellationToken
,
Task
<
Solution
>>
createChangedSolution
)
:
base
(
title
,
createChanged
Solution
)
{
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录