Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
146b391d
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,发现更多精彩内容 >>
提交
146b391d
编写于
1月 30, 2017
作者:
C
CyrusNajmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Format 'unsafe' blocks according to user settings.
上级
bb988f78
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
20 deletion
+51
-20
src/Workspaces/CSharp/Portable/Formatting/Rules/NewLineUserSettingFormattingRule.cs
...able/Formatting/Rules/NewLineUserSettingFormattingRule.cs
+29
-13
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
+22
-7
未找到文件。
src/Workspaces/CSharp/Portable/Formatting/Rules/NewLineUserSettingFormattingRule.cs
浏览文件 @
146b391d
...
...
@@ -11,19 +11,35 @@ internal class NewLineUserSettingFormattingRule : BaseFormattingRule
{
private
bool
IsControlBlock
(
SyntaxNode
node
)
{
var
parent
=
node
!=
null
?
node
.
Parent
:
null
;
return
(
node
!=
null
&&
node
.
Kind
()
==
SyntaxKind
.
SwitchStatement
)
||
(
parent
!=
null
&&
(
parent
.
Kind
()
==
SyntaxKind
.
IfStatement
||
parent
.
Kind
()
==
SyntaxKind
.
ElseClause
||
parent
.
Kind
()
==
SyntaxKind
.
WhileStatement
||
parent
.
Kind
()
==
SyntaxKind
.
DoStatement
||
parent
.
Kind
()
==
SyntaxKind
.
ForEachStatement
||
parent
.
Kind
()
==
SyntaxKind
.
ForEachVariableStatement
||
parent
.
Kind
()
==
SyntaxKind
.
UsingStatement
||
parent
.
Kind
()
==
SyntaxKind
.
ForStatement
||
parent
.
Kind
()
==
SyntaxKind
.
TryStatement
||
parent
.
Kind
()
==
SyntaxKind
.
CatchClause
||
parent
.
Kind
()
==
SyntaxKind
.
FinallyClause
||
parent
.
Kind
()
==
SyntaxKind
.
LockStatement
||
parent
.
Kind
()
==
SyntaxKind
.
CheckedStatement
||
parent
.
Kind
()
==
SyntaxKind
.
UncheckedStatement
||
parent
.
Kind
()
==
SyntaxKind
.
SwitchSection
||
parent
.
Kind
()
==
SyntaxKind
.
FixedStatement
));
if
(
node
.
Kind
()
==
SyntaxKind
.
SwitchStatement
)
{
return
true
;
}
var
parentKind
=
node
?.
Parent
.
Kind
();
switch
(
parentKind
.
GetValueOrDefault
())
{
case
SyntaxKind
.
IfStatement
:
case
SyntaxKind
.
ElseClause
:
case
SyntaxKind
.
WhileStatement
:
case
SyntaxKind
.
DoStatement
:
case
SyntaxKind
.
ForEachStatement
:
case
SyntaxKind
.
ForEachVariableStatement
:
case
SyntaxKind
.
UsingStatement
:
case
SyntaxKind
.
ForStatement
:
case
SyntaxKind
.
TryStatement
:
case
SyntaxKind
.
CatchClause
:
case
SyntaxKind
.
FinallyClause
:
case
SyntaxKind
.
LockStatement
:
case
SyntaxKind
.
CheckedStatement
:
case
SyntaxKind
.
UncheckedStatement
:
case
SyntaxKind
.
SwitchSection
:
case
SyntaxKind
.
FixedStatement
:
case
SyntaxKind
.
UnsafeStatement
:
return
true
;
default
:
return
false
;
}
}
public
override
AdjustSpacesOperation
GetAdjustSpacesOperation
(
SyntaxToken
previousToken
,
SyntaxToken
currentToken
,
OptionSet
optionSet
,
NextOperation
<
AdjustSpacesOperation
>
nextOperation
)
...
...
src/Workspaces/CSharpTest/Formatting/FormattingTests.cs
浏览文件 @
146b391d
...
...
@@ -1538,17 +1538,18 @@ public class foo : System.Object
}
[
WorkItem
(
751789
,
"http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/751789"
)]
[
WorkItem
(
8808
,
"https://developercommunity.visualstudio.com/content/problem/8808/c-structure-guide-lines-for-unsafe-fixed.html"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Formatting
)]
public
async
Task
NewLineForOpenBracesNonDefault
()
{
var
changingOptions
=
new
Dictionary
<
OptionKey
,
object
>();
changingOptions
.
Add
(
CSharpFormattingOptions
.
NewLinesForBracesInTypes
,
false
);
changingOptions
.
Add
(
CSharpFormattingOptions
.
NewLinesForBracesInMethods
,
false
);
changingOptions
.
Add
(
CSharpFormattingOptions
.
NewLinesForBracesInAnonymousMethods
,
false
);
changingOptions
.
Add
(
CSharpFormattingOptions
.
NewLinesForBracesInControlBlocks
,
false
);
changingOptions
.
Add
(
CSharpFormattingOptions
.
NewLinesForBracesInAnonymousTypes
,
false
);
changingOptions
.
Add
(
CSharpFormattingOptions
.
NewLinesForBracesInObjectCollectionArrayInitializers
,
false
);
changingOptions
.
Add
(
CSharpFormattingOptions
.
NewLinesForBracesInLambdaExpressionBody
,
false
);
changingOptions
.
Add
(
NewLinesForBracesInTypes
,
false
);
changingOptions
.
Add
(
NewLinesForBracesInMethods
,
false
);
changingOptions
.
Add
(
NewLinesForBracesInAnonymousMethods
,
false
);
changingOptions
.
Add
(
NewLinesForBracesInControlBlocks
,
false
);
changingOptions
.
Add
(
NewLinesForBracesInAnonymousTypes
,
false
);
changingOptions
.
Add
(
NewLinesForBracesInObjectCollectionArrayInitializers
,
false
);
changingOptions
.
Add
(
NewLinesForBracesInLambdaExpressionBody
,
false
);
await
AssertFormatAsync
(
@"class f00 {
void br() {
Func<int, int> ret = x => {
...
...
@@ -1582,6 +1583,12 @@ public async Task NewLineForOpenBracesNonDefault()
default:
break;
}
unsafe {
}
fixed (int* p = &i) {
}
}
}
...
...
@@ -1635,6 +1642,14 @@ public class foo : System.Object {
default:
break;
}
unsafe
{
}
fixed (int* p = &i)
{
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录