Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
0694d5cc
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,发现更多精彩内容 >>
提交
0694d5cc
编写于
10月 29, 2016
作者:
C
CyrusNajmabadi
提交者:
GitHub
10月 29, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #14805 from jbevain/obj-initializer-csharp-version
Disable Use Object Initializer diagnostic prior to C# 3
上级
6a3988ea
3cc38f0b
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
0 deletion
+37
-0
src/EditorFeatures/CSharpTest/UseObjectInitializer/UseObjectInitializerTests.cs
...arpTest/UseObjectInitializer/UseObjectInitializerTests.cs
+18
-0
src/Features/CSharp/Portable/UseObjectInitializer/CSharpUseObjectInitializerDiagnosticAnalyzer.cs
...itializer/CSharpUseObjectInitializerDiagnosticAnalyzer.cs
+7
-0
src/Features/Core/Portable/UseObjectInitializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs
...ializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs
+7
-0
src/Features/VisualBasic/Portable/UseObjectInitializer/VisualBasicUseObjectInitializerDiagnosticAnalyzer.vb
...izer/VisualBasicUseObjectInitializerDiagnosticAnalyzer.vb
+5
-0
未找到文件。
src/EditorFeatures/CSharpTest/UseObjectInitializer/UseObjectInitializerTests.cs
浏览文件 @
0694d5cc
...
...
@@ -3,6 +3,7 @@
using
System
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CodeFixes
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.CodeAnalysis.CSharp.UseObjectInitializer
;
using
Microsoft.CodeAnalysis.Diagnostics
;
using
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Diagnostics
;
...
...
@@ -193,6 +194,23 @@ void M()
}"
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseObjectInitializer
)]
public
async
Task
TestMissingBeforeCSharp3
()
{
await
TestMissingAsync
(
@"
class C
{
int i;
int j;
void M()
{
var c = [||]new C();
c.j = 1;
}
}"
,
parseOptions
:
CSharpParseOptions
.
Default
.
WithLanguageVersion
(
LanguageVersion
.
CSharp2
));
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseObjectInitializer
)]
public
async
Task
TestFixAllInDocument
()
{
...
...
src/Features/CSharp/Portable/UseObjectInitializer/CSharpUseObjectInitializerDiagnosticAnalyzer.cs
浏览文件 @
0694d5cc
...
...
@@ -21,6 +21,13 @@ internal class CSharpUseObjectInitializerDiagnosticAnalyzer :
{
protected
override
bool
FadeOutOperatorToken
=>
true
;
protected
override
bool
AreObjectInitializersSupported
(
SyntaxNodeAnalysisContext
context
)
{
// object initializers are only available in C# 3.0 and above. Don't offer this refactoring
// in projects targeting a lesser version.
return
((
CSharpParseOptions
)
context
.
Node
.
SyntaxTree
.
Options
).
LanguageVersion
>=
LanguageVersion
.
CSharp3
;
}
protected
override
SyntaxKind
GetObjectCreationSyntaxKind
()
=>
SyntaxKind
.
ObjectCreationExpression
;
protected
override
ISyntaxFactsService
GetSyntaxFactsService
()
=>
CSharpSyntaxFactsService
.
Instance
;
...
...
src/Features/Core/Portable/UseObjectInitializer/AbstractUseObjectInitializerDiagnosticAnalyzer.cs
浏览文件 @
0694d5cc
...
...
@@ -44,8 +44,15 @@ public override void Initialize(AnalysisContext context)
protected
abstract
TSyntaxKind
GetObjectCreationSyntaxKind
();
protected
abstract
bool
AreObjectInitializersSupported
(
SyntaxNodeAnalysisContext
context
);
private
void
AnalyzeNode
(
SyntaxNodeAnalysisContext
context
)
{
if
(!
AreObjectInitializersSupported
(
context
))
{
return
;
}
var
objectCreationExpression
=
(
TObjectCreationExpressionSyntax
)
context
.
Node
;
var
language
=
objectCreationExpression
.
Language
;
...
...
src/Features/VisualBasic/Portable/UseObjectInitializer/VisualBasicUseObjectInitializerDiagnosticAnalyzer.vb
浏览文件 @
0694d5cc
...
...
@@ -23,6 +23,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UseObjectInitializer
End
Get
End
Property
Protected
Overrides
Function
AreObjectInitializersSupported
(
context
As
SyntaxNodeAnalysisContext
)
As
Boolean
'Object Initializers are supported in all the versions of Visual Basic we support
Return
True
End
Function
Protected
Overrides
Function
GetObjectCreationSyntaxKind
()
As
SyntaxKind
Return
SyntaxKind
.
ObjectCreationExpression
End
Function
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录