Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
883ffdb8
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,体验更适合开发者的 AI 搜索 >>
提交
883ffdb8
编写于
7月 09, 2020
作者:
M
Manish Vasani
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable and fix IDE0007 violations (Prefer "var")
上级
c54743b7
变更
15
隐藏空白更改
内联
并排
Showing
15 changed file
with
54 addition
and
48 deletion
+54
-48
.editorconfig
.editorconfig
+7
-1
src/EditorFeatures/CSharp.Wpf/Interactive/CSharpSendToInteractiveSubmissionProvider.cs
.../Interactive/CSharpSendToInteractiveSubmissionProvider.cs
+2
-2
src/EditorFeatures/CSharpTest/CodeActions/ConvertLinq/ConvertLinqQueryToForEachTests.cs
...CodeActions/ConvertLinq/ConvertLinqQueryToForEachTests.cs
+12
-12
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs
.../CompletionProviders/TypeImportCompletionProviderTests.cs
+4
-4
src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs
...DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs
+1
-1
src/EditorFeatures/CSharpTest/EditAndContinue/ActiveStatementTests.cs
...atures/CSharpTest/EditAndContinue/ActiveStatementTests.cs
+14
-14
src/EditorFeatures/CSharpTest/EditAndContinue/BreakpointSpansTests.cs
...atures/CSharpTest/EditAndContinue/BreakpointSpansTests.cs
+1
-1
src/EditorFeatures/CSharpTest/EditAndContinue/TopLevelEditingTests.cs
...atures/CSharpTest/EditAndContinue/TopLevelEditingTests.cs
+4
-4
src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
...itorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
+1
-1
src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs
...rFeatures/Core/Implementation/CodeFixes/CodeFixService.cs
+2
-2
src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTrackingService.cs
...ntation/EditAndContinue/ActiveStatementTrackingService.cs
+2
-2
src/EditorFeatures/Core/Shared/Extensions/InferredIndentationExtensions.cs
...s/Core/Shared/Extensions/InferredIndentationExtensions.cs
+1
-1
src/EditorFeatures/Test/Diagnostics/IDEDiagnosticIDConfigurationTests.cs
...res/Test/Diagnostics/IDEDiagnosticIDConfigurationTests.cs
+1
-1
src/EditorFeatures/Test/EditAndContinue/Helpers/SymReaderTestHelpers.cs
...ures/Test/EditAndContinue/Helpers/SymReaderTestHelpers.cs
+1
-1
src/EditorFeatures/TestUtilities/Workspaces/TestWorkspace_XmlConsumption.cs
.../TestUtilities/Workspaces/TestWorkspace_XmlConsumption.cs
+1
-1
未找到文件。
.editorconfig
浏览文件 @
883ffdb8
...
...
@@ -300,4 +300,10 @@ dotnet_diagnostic.IDE0051.severity = warning
dotnet_diagnostic.IDE0052.severity = warning
# IDE0059: Unnecessary assignment to a value
dotnet_diagnostic.IDE0059.severity = warning
\ No newline at end of file
dotnet_diagnostic.IDE0059.severity = warning
# Prefer "var" everywhere
dotnet_diagnostic.IDE0007.severity = warning
csharp_style_var_for_built_in_types = true:warning
csharp_style_var_when_type_is_apparent = true:warning
csharp_style_var_elsewhere = true:warning
\ No newline at end of file
src/EditorFeatures/CSharp.Wpf/Interactive/CSharpSendToInteractiveSubmissionProvider.cs
浏览文件 @
883ffdb8
...
...
@@ -28,14 +28,14 @@ public CSharpSendToInteractiveSubmissionProvider()
protected
override
bool
CanParseSubmission
(
string
code
)
{
ParseOptions
options
=
CSharpParseOptions
.
Default
.
WithKind
(
SourceCodeKind
.
Script
);
SyntaxTree
tree
=
SyntaxFactory
.
ParseSyntaxTree
(
code
,
options
);
var
tree
=
SyntaxFactory
.
ParseSyntaxTree
(
code
,
options
);
return
tree
.
HasCompilationUnitRoot
&&
!
tree
.
GetDiagnostics
().
Any
(
diagnostic
=>
diagnostic
.
Severity
==
DiagnosticSeverity
.
Error
);
}
protected
override
IEnumerable
<
TextSpan
>
GetExecutableSyntaxTreeNodeSelection
(
TextSpan
selectionSpan
,
SyntaxNode
root
)
{
SyntaxNode
expandedNode
=
GetSyntaxNodeForSubmission
(
selectionSpan
,
root
);
var
expandedNode
=
GetSyntaxNodeForSubmission
(
selectionSpan
,
root
);
return
expandedNode
!=
null
?
new
TextSpan
[]
{
expandedNode
.
Span
}
:
Array
.
Empty
<
TextSpan
>();
...
...
src/EditorFeatures/CSharpTest/CodeActions/ConvertLinq/ConvertLinqQueryToForEachTests.cs
浏览文件 @
883ffdb8
...
...
@@ -4190,7 +4190,7 @@ IEnumerable<int> M(IEnumerable<int> nums)
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsConvertQueryToForEach
)]
public
async
Task
EnumerableFunctionDoesNotUseLocalFunctionName
()
{
string
source
=
@"
var
source
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4204,7 +4204,7 @@ public static void Main(string[] args)
void enumerable() { }
}
}"
;
string
output
=
@"
var
output
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4232,7 +4232,7 @@ IEnumerable<int> enumerable1()
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsConvertQueryToForEach
)]
public
async
Task
EnumerableFunctionCanUseLocalFunctionParameterName
()
{
string
source
=
@"
var
source
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4246,7 +4246,7 @@ public static void Main(string[] args)
void M(IEnumerable<int> enumerable) { }
}
}"
;
string
output
=
@"
var
output
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4274,7 +4274,7 @@ IEnumerable<int> enumerable()
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsConvertQueryToForEach
)]
public
async
Task
EnumerableFunctionDoesNotUseLambdaParameterNameWithCSharpLessThan8
()
{
string
source
=
@"
var
source
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4288,7 +4288,7 @@ public static void Main(string[] args)
Action<int> myLambda = enumerable => { };
}
}"
;
string
output
=
@"
var
output
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4316,7 +4316,7 @@ IEnumerable<int> enumerable1()
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsConvertQueryToForEach
)]
public
async
Task
EnumerableFunctionCanUseLambdaParameterNameInCSharp8
()
{
string
source
=
@"
var
source
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4330,7 +4330,7 @@ public static void Main(string[] args)
Action<int> myLambda = enumerable => { };
}
}"
;
string
output
=
@"
var
output
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4362,7 +4362,7 @@ IEnumerable<int> enumerable()
[
WorkItem
(
35180
,
"https://github.com/dotnet/roslyn/issues/35180"
)]
public
async
Task
DeclarationSelection
()
{
string
source
=
@"
var
source
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4374,7 +4374,7 @@ public static void Main(string[] args)
var r = [|from i in c select i+1;|]
}
}"
;
string
output
=
@"
var
output
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4401,7 +4401,7 @@ IEnumerable<int> enumerable()
[
WorkItem
(
35180
,
"https://github.com/dotnet/roslyn/issues/35180"
)]
public
async
Task
LocalAssignmentSelection
()
{
string
source
=
@"
var
source
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
@@ -4414,7 +4414,7 @@ public static void Main(string[] args)
[|r = from i in c select i+1;|]
}
}"
;
string
output
=
@"
var
output
=
@"
using System;
using System.Collections.Generic;
using System.Linq;
...
...
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs
浏览文件 @
883ffdb8
...
...
@@ -1020,7 +1020,7 @@ namespace Test
class Program { }
}"
;
string
expectedCodeAfterCommit
=
@"
var
expectedCodeAfterCommit
=
@"
using Foo;
namespace Test
...
...
@@ -1082,7 +1082,7 @@ class Program
}
}"
;
string
expectedCodeAfterCommit
=
@"
var
expectedCodeAfterCommit
=
@"
using Foo;
namespace Test
...
...
@@ -1141,7 +1141,7 @@ namespace Test
class Program { }
}"
;
string
expectedCodeAfterCommit
=
@"
var
expectedCodeAfterCommit
=
@"
using Foo;
namespace Test
...
...
@@ -1203,7 +1203,7 @@ class Program
}
}"
;
string
expectedCodeAfterCommit
=
@"
var
expectedCodeAfterCommit
=
@"
using Foo;
namespace Test
...
...
src/EditorFeatures/CSharpTest/Diagnostics/DiagnosticAnalyzerDriver/DiagnosticAnalyzerDriverTests.cs
浏览文件 @
883ffdb8
...
...
@@ -624,7 +624,7 @@ public async Task TestNuGetAndVsixAnalyzer_MultipleNuGetAnalyzersCollectivelyRep
diagnostics
.
Verify
(
expectedDiagnostics
.
Select
(
d
=>
d
.
diagnostic
).
ToArray
());
int
index
=
0
;
var
index
=
0
;
foreach
(
var
(
_
,
expectedMessage
)
in
expectedDiagnostics
)
{
Assert
.
Equal
(
expectedMessage
,
diagnostics
[
index
].
GetMessage
());
...
...
src/EditorFeatures/CSharpTest/EditAndContinue/ActiveStatementTests.cs
浏览文件 @
883ffdb8
...
...
@@ -4087,7 +4087,7 @@ static unsafe void Main(string[] args)
[
Fact
]
public
void
ForEach_Update_Nullable
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void F()
...
...
@@ -4100,7 +4100,7 @@ static void F()
}
}
"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void F()
...
...
@@ -4122,7 +4122,7 @@ static void F()
[
Fact
]
public
void
ForEach_DeleteBody
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void F()
...
...
@@ -4131,7 +4131,7 @@ static void F()
}
}
"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void F()
...
...
@@ -4149,7 +4149,7 @@ static void F()
[
Fact
]
public
void
ForEachVariable_DeleteBody
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void F()
...
...
@@ -4158,7 +4158,7 @@ static void F()
}
}
"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void F()
...
...
@@ -5442,7 +5442,7 @@ public static void Main()
[
Fact
]
public
void
DoWhileBody_Delete
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void F()
...
...
@@ -5451,7 +5451,7 @@ static void F()
}
}
"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void F()
...
...
@@ -10437,7 +10437,7 @@ static void F(object o1, object o2)
[
Fact
]
public
void
ChangeLocalNullableToNonNullable
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void F()
...
...
@@ -10446,7 +10446,7 @@ static void F()
}
}
"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void F()
...
...
@@ -10464,7 +10464,7 @@ static void F()
[
Fact
]
public
void
ChangeLocalNonNullableToNullable
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void F()
...
...
@@ -10473,7 +10473,7 @@ static void F()
}
}
"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void F()
...
...
@@ -10615,7 +10615,7 @@ public static void F()
[
Fact
]
public
void
Block_Delete
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
public static void F()
...
...
@@ -10626,7 +10626,7 @@ public static void F()
}
}
"
;
string
src2
=
@"
var
src2
=
@"
class C
{
public static void F()
...
...
src/EditorFeatures/CSharpTest/EditAndContinue/BreakpointSpansTests.cs
浏览文件 @
883ffdb8
...
...
@@ -74,7 +74,7 @@ public static IEnumerable<TextSpan> GetBreakpointSequence(SyntaxNode root, int p
{
TextSpan
lastSpan
=
default
;
var
endPosition
=
root
.
Span
.
End
;
for
(
int
p
=
position
;
p
<
endPosition
;
p
++)
for
(
var
p
=
position
;
p
<
endPosition
;
p
++)
{
if
(
BreakpointSpans
.
TryGetClosestBreakpointSpan
(
root
,
p
,
out
var
span
)
&&
span
.
Start
>
lastSpan
.
Start
)
{
...
...
src/EditorFeatures/CSharpTest/EditAndContinue/TopLevelEditingTests.cs
浏览文件 @
883ffdb8
...
...
@@ -2847,14 +2847,14 @@ static void Main(string[] b)
[
Fact
]
public
void
MethodUpdate_UpdateParameterToNullable
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void M(string s)
{
}
}"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void M(string? s)
...
...
@@ -2873,7 +2873,7 @@ static void M(string? s)
[
Fact
]
public
void
MethodUpdate_UpdateParameterToNonNullable
()
{
string
src1
=
@"
var
src1
=
@"
class C
{
static void M(string? s)
...
...
@@ -2881,7 +2881,7 @@ static void M(string? s)
}
}"
;
string
src2
=
@"
var
src2
=
@"
class C
{
static void M(string s)
...
...
src/EditorFeatures/CSharpTest/TypeInferrer/TypeInferrerTests.cs
浏览文件 @
883ffdb8
...
...
@@ -33,7 +33,7 @@ protected override async Task TestWorkerAsync(Document document, TextSpan textSp
if
(
mode
==
TestMode
.
Position
)
{
int
position
=
node
?.
SpanStart
??
textSpan
.
Start
;
var
position
=
node
?.
SpanStart
??
textSpan
.
Start
;
inferredType
=
typeInference
.
InferType
(
await
document
.
ReuseExistingSpeculativeModelAsync
(
position
,
CancellationToken
.
None
),
position
,
objectAsDefault
:
true
,
cancellationToken
:
CancellationToken
.
None
);
}
else
...
...
src/EditorFeatures/Core/Implementation/CodeFixes/CodeFixService.cs
浏览文件 @
883ffdb8
...
...
@@ -205,11 +205,11 @@ public async Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(Document docu
if
(
result
.
Count
>
0
&&
_fixerPriorityMap
.
TryGetValue
(
document
.
Project
.
Language
,
out
var
fixersForLanguage
))
{
// sort the result to the order defined by the fixers
ImmutableDictionary
<
CodeFixProvider
,
int
>
priorityMap
=
fixersForLanguage
.
Value
;
var
priorityMap
=
fixersForLanguage
.
Value
;
result
.
Sort
((
d1
,
d2
)
=>
GetValue
(
d1
).
CompareTo
(
GetValue
(
d2
)));
int
GetValue
(
CodeFixCollection
c
)
=>
priorityMap
.
TryGetValue
((
CodeFixProvider
)
c
.
Provider
,
out
var
value
)
?
value
:
int
.
MaxValue
;
=>
priorityMap
!
.
TryGetValue
((
CodeFixProvider
)
c
.
Provider
,
out
var
value
)
?
value
:
int
.
MaxValue
;
}
// TODO (https://github.com/dotnet/roslyn/issues/4932): Don't restrict CodeFixes in Interactive
...
...
src/EditorFeatures/Core/Implementation/EditAndContinue/ActiveStatementTrackingService.cs
浏览文件 @
883ffdb8
...
...
@@ -206,7 +206,7 @@ private async Task TrackActiveSpansAsync(CancellationToken cancellationToken)
lock
(
_trackingSpans
)
{
for
(
int
i
=
0
;
i
<
baseActiveStatementSpans
.
Length
;
i
++)
for
(
var
i
=
0
;
i
<
baseActiveStatementSpans
.
Length
;
i
++)
{
var
document
=
currentSolution
.
GetDocument
(
openDocumentIds
[
i
]);
if
(
document
==
null
)
...
...
@@ -327,7 +327,7 @@ internal async Task<ImmutableArray<ActiveStatementTrackingSpan>> GetLatestSpansA
lock
(
_trackingSpans
)
{
bool
hasExistingSpans
=
_trackingSpans
.
TryGetValue
(
document
.
Id
,
out
var
oldSpans
);
var
hasExistingSpans
=
_trackingSpans
.
TryGetValue
(
document
.
Id
,
out
var
oldSpans
);
if
(
activeStatementSpans
.
IsDefault
)
{
...
...
src/EditorFeatures/Core/Shared/Extensions/InferredIndentationExtensions.cs
浏览文件 @
883ffdb8
...
...
@@ -27,7 +27,7 @@ internal static class InferredIndentationOptions
if
(
snapshot
!=
null
)
{
indentationManagerService
.
GetIndentation
(
snapshot
.
TextBuffer
,
explicitFormat
,
out
bool
convertTabsToSpaces
,
out
int
tabSize
,
out
int
indentSize
);
indentationManagerService
.
GetIndentation
(
snapshot
.
TextBuffer
,
explicitFormat
,
out
var
convertTabsToSpaces
,
out
var
tabSize
,
out
var
indentSize
);
options
=
options
.
WithChangedOption
(
FormattingOptions
.
UseTabs
,
!
convertTabsToSpaces
)
.
WithChangedOption
(
FormattingOptions
.
IndentationSize
,
indentSize
)
...
...
src/EditorFeatures/Test/Diagnostics/IDEDiagnosticIDConfigurationTests.cs
浏览文件 @
883ffdb8
...
...
@@ -76,7 +76,7 @@ public class IDEDiagnosticIDConfigurationTests
expectedLines
=
expected
.
Split
(
new
[]
{
Environment
.
NewLine
},
StringSplitOptions
.
RemoveEmptyEntries
);
Assert
.
True
(
expectedLines
.
Length
%
2
==
0
);
var
expectedMap
=
new
Dictionary
<
string
,
string
>();
for
(
int
i
=
0
;
i
<
expectedLines
.
Length
;
i
+=
2
)
for
(
var
i
=
0
;
i
<
expectedLines
.
Length
;
i
+=
2
)
{
expectedMap
.
Add
(
expectedLines
[
i
].
Trim
(),
expectedLines
[
i
+
1
].
Trim
());
}
...
...
src/EditorFeatures/Test/EditAndContinue/Helpers/SymReaderTestHelpers.cs
浏览文件 @
883ffdb8
...
...
@@ -51,7 +51,7 @@ public static ISymUnmanagedReader5 OpenDummySymReader(ImmutableArray<byte> pdbIm
var
pdbStreamCom
=
SymUnmanagedStreamFactory
.
CreateStream
(
pdbStream
);
if
(
pdbImage
.
Length
>
4
&&
pdbImage
[
0
]
==
'B'
&&
pdbImage
[
1
]
==
'S'
&&
pdbImage
[
2
]
==
'J'
&&
pdbImage
[
3
]
==
'B'
)
{
int
hr
=
symBinder
.
GetReaderFromPdbStream
(
metadataImportProvider
,
pdbStreamCom
,
out
var
symReader
);
var
hr
=
symBinder
.
GetReaderFromPdbStream
(
metadataImportProvider
,
pdbStreamCom
,
out
var
symReader
);
Assert
.
Equal
(
0
,
hr
);
return
(
ISymUnmanagedReader5
)
symReader
;
}
...
...
src/EditorFeatures/TestUtilities/Workspaces/TestWorkspace_XmlConsumption.cs
浏览文件 @
883ffdb8
...
...
@@ -765,7 +765,7 @@ private static CompilationOptions CreateCompilationOptions(TestWorkspace workspa
HostLanguageServices
languageServiceProvider
,
ImmutableArray
<
string
>
roles
)
{
string
markupCode
=
documentElement
.
NormalizedValue
();
var
markupCode
=
documentElement
.
NormalizedValue
();
var
folders
=
GetFolders
(
documentElement
);
var
optionsElement
=
documentElement
.
Element
(
ParseOptionsElementName
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录