Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
54acac73
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,发现更多精彩内容 >>
提交
54acac73
编写于
2月 23, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Properly handle adding multiple usings when there is a banner at the top of the file
上级
3799c349
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
64 addition
and
11 deletion
+64
-11
src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs
...est/ImplementAbstractClass/ImplementAbstractClassTests.cs
+47
-0
src/Workspaces/CSharp/Portable/Extensions/CompilationUnitSyntaxExtensions.cs
...rp/Portable/Extensions/CompilationUnitSyntaxExtensions.cs
+17
-11
未找到文件。
src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs
浏览文件 @
54acac73
...
...
@@ -1544,5 +1544,52 @@ class Derived : Base
public override int Prop => throw new NotImplementedException();
}"
,
options
:
Option
(
ImplementTypeOptions
.
InsertionBehavior
,
ImplementTypeInsertionBehavior
.
AtTheEnd
));
}
[
WorkItem
(
17274
,
"https://github.com/dotnet/roslyn/issues/17274"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsImplementAbstractClass
)]
public
async
Task
TestAddedUsingWithBanner1
()
{
await
TestAsync
(
@"// Copyright ...
using Microsoft.Win32;
namespace My
{
public abstract class Foo
{
public abstract void Bar(System.Collections.Generic.List<object> values);
}
public class [|Foo2|] : Foo // Implement Abstract Class
{
}
}"
,
@"// Copyright ...
using System;
using System.Collections.Generic;
using Microsoft.Win32;
namespace My
{
public abstract class Foo
{
public abstract void Bar(System.Collections.Generic.List<object> values);
}
public class Foo2 : Foo // Implement Abstract Class
{
public override void Bar(List<object> values)
{
throw new NotImplementedException();
}
}
}"
,
compareTokens
:
false
);
}
#if false
#endif
}
}
\ No newline at end of file
src/Workspaces/CSharp/Portable/Extensions/CompilationUnitSyntaxExtensions.cs
浏览文件 @
54acac73
...
...
@@ -154,15 +154,21 @@ private static TextSpan GetUsingsSpan(CompilationUnitSyntax root, NamespaceDecla
firstToken
.
LeadingTrivia
.
Where
(
t
=>
!
IsDocCommentOrElastic
(
t
)));
usings
[
0
]
=
newFirstUsing
;
}
else
if
(
usings
[
0
]
!=
root
.
Usings
[
0
])
else
{
// We added a new first-using. Take the trivia on the existing first using
// And move it to the new using.
var
newFirstUsing
=
usings
[
0
].
WithLeadingTrivia
(
usings
[
1
].
GetLeadingTrivia
())
.
WithAppendedTrailingTrivia
(
SyntaxFactory
.
ElasticCarriageReturnLineFeed
);
usings
[
0
]
=
newFirstUsing
;
usings
[
1
]
=
usings
[
1
].
WithoutLeadingTrivia
();
var
originalFirstUsing
=
root
.
Usings
[
0
];
if
(
usings
[
0
]
!=
originalFirstUsing
)
{
// We added a new first-using. Take the trivia on the existing first using
// And move it to the new using.
var
originalFirstUsingCurrentIndex
=
usings
.
IndexOf
(
originalFirstUsing
);
var
newFirstUsing
=
usings
[
0
].
WithLeadingTrivia
(
originalFirstUsing
.
GetLeadingTrivia
())
.
WithAppendedTrailingTrivia
(
SyntaxFactory
.
ElasticCarriageReturnLineFeed
);
usings
[
0
]
=
newFirstUsing
;
usings
[
originalFirstUsingCurrentIndex
]
=
originalFirstUsing
.
WithoutLeadingTrivia
();
}
}
}
...
...
@@ -181,9 +187,9 @@ private static bool IsDocCommentOrElastic(SyntaxTrivia t)
// We need to try and not place the using inside of a directive if possible.
var
usings
=
new
List
<
UsingDirectiveSyntax
>();
var
endOfList
=
root
.
Usings
.
Count
-
1
;
int
startOfLastDirective
=
-
1
;
int
endOfLastDirective
=
-
1
;
for
(
int
i
=
0
;
i
<
root
.
Usings
.
Count
;
i
++)
var
startOfLastDirective
=
-
1
;
var
endOfLastDirective
=
-
1
;
for
(
var
i
=
0
;
i
<
root
.
Usings
.
Count
;
i
++)
{
if
(
root
.
Usings
[
i
].
GetLeadingTrivia
().
Any
(
trivia
=>
trivia
.
IsKind
(
SyntaxKind
.
IfDirectiveTrivia
)))
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录