Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6716c84a
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 搜索 >>
提交
6716c84a
编写于
4月 26, 2020
作者:
A
Alireza Habibi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move files and add code style option
上级
df1c6e77
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
63 addition
and
7 deletion
+63
-7
src/Analyzers/CSharp/Analyzers/CSharpAnalyzers.projitems
src/Analyzers/CSharp/Analyzers/CSharpAnalyzers.projitems
+3
-0
src/Analyzers/CSharp/Analyzers/UsePatternCombinators/AnalyzedPattern.cs
...CSharp/Analyzers/UsePatternCombinators/AnalyzedPattern.cs
+0
-0
src/Analyzers/CSharp/Analyzers/UsePatternCombinators/CSharpUsePatternCombinatorsAnalyzer.cs
...PatternCombinators/CSharpUsePatternCombinatorsAnalyzer.cs
+0
-0
src/Analyzers/CSharp/Analyzers/UsePatternCombinators/CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs
...binators/CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs
+13
-5
src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems
src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems
+1
-0
src/Analyzers/CSharp/CodeFixes/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
...Combinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
+0
-0
src/EditorFeatures/Test/Diagnostics/IDEDiagnosticIDConfigurationTests.cs
...res/Test/Diagnostics/IDEDiagnosticIDConfigurationTests.cs
+6
-0
src/VisualStudio/CSharp/Impl/CSharpVSResources.resx
src/VisualStudio/CSharp/Impl/CSharpVSResources.resx
+3
-0
src/VisualStudio/CSharp/Impl/Options/AutomationObject.cs
src/VisualStudio/CSharp/Impl/Options/AutomationObject.cs
+6
-0
src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs
...alStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs
+23
-2
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CodeStyle/CSharpCodeStyleOptions.cs
...sions/Compiler/CSharp/CodeStyle/CSharpCodeStyleOptions.cs
+8
-0
未找到文件。
src/Analyzers/CSharp/Analyzers/CSharpAnalyzers.projitems
浏览文件 @
6716c84a
...
...
@@ -86,6 +86,9 @@
<Compile
Include=
"$(MSBuildThisFileDirectory)UseLocalFunction\CSharpUseLocalFunctionDiagnosticAnalyzer.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UseNullPropagation\CSharpUseNullPropagationDiagnosticAnalyzer.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UseObjectInitializer\CSharpUseObjectInitializerDiagnosticAnalyzer.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternCombinators\AnalyzedPattern.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternCombinators\CSharpUsePatternCombinatorsAnalyzer.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternCombinators\CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternMatching\CSharpAsAndNullCheckDiagnosticAnalyzer.Analyzer.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternMatching\CSharpAsAndNullCheckDiagnosticAnalyzer.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternMatching\CSharpIsAndCastCheckDiagnosticAnalyzer.cs"
/>
...
...
src/
Features/CSharp/Portable
/UsePatternCombinators/AnalyzedPattern.cs
→
src/
Analyzers/CSharp/Analyzers
/UsePatternCombinators/AnalyzedPattern.cs
浏览文件 @
6716c84a
文件已移动
src/
Features/CSharp/Portable
/UsePatternCombinators/CSharpUsePatternCombinatorsAnalyzer.cs
→
src/
Analyzers/CSharp/Analyzers
/UsePatternCombinators/CSharpUsePatternCombinatorsAnalyzer.cs
浏览文件 @
6716c84a
文件已移动
src/
Features/CSharp/Portable
/UsePatternCombinators/CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs
→
src/
Analyzers/CSharp/Analyzers
/UsePatternCombinators/CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs
浏览文件 @
6716c84a
...
...
@@ -6,6 +6,7 @@
using
System.Linq
;
using
Microsoft.CodeAnalysis.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp.CodeStyle
;
using
Microsoft.CodeAnalysis.CSharp.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Shared.Extensions
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
...
...
@@ -21,9 +22,10 @@ internal sealed class CSharpUsePatternCombinatorsDiagnosticAnalyzer :
{
public
CSharpUsePatternCombinatorsDiagnosticAnalyzer
()
:
base
(
IDEDiagnosticIds
.
UsePatternCombinatorsDiagnosticId
,
option
:
null
,
new
LocalizableResourceString
(
nameof
(
CSharpAnalyzersResources
.
Use_pattern_matching
),
CSharpAnalyzersResources
.
ResourceManager
,
typeof
(
CSharpAnalyzersResources
)))
CSharpCodeStyleOptions
.
PreferPatternMatching
,
LanguageNames
.
CSharp
,
new
LocalizableResourceString
(
nameof
(
CSharpAnalyzersResources
.
Use_pattern_matching
),
CSharpAnalyzersResources
.
ResourceManager
,
typeof
(
CSharpAnalyzersResources
)),
new
LocalizableResourceString
(
nameof
(
CSharpAnalyzersResources
.
Use_pattern_matching
),
CSharpAnalyzersResources
.
ResourceManager
,
typeof
(
CSharpAnalyzersResources
)))
{
}
...
...
@@ -69,15 +71,21 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
// TODO need an option for user to disable the feature
var
parentNode
=
context
.
Node
;
var
syntaxTree
=
parentNode
.
SyntaxTree
;
var
cancellationToken
=
context
.
CancellationToken
;
if
(!((
CSharpParseOptions
)
parentNode
.
SyntaxTree
.
Options
).
LanguageVersion
.
IsCSharp9OrAbove
())
if
(!((
CSharpParseOptions
)
syntaxTree
.
Options
).
LanguageVersion
.
IsCSharp9OrAbove
())
return
;
var
styleOption
=
context
.
Options
.
GetOption
(
CSharpCodeStyleOptions
.
PreferPatternMatching
,
syntaxTree
,
cancellationToken
);
if
(!
styleOption
.
Value
)
return
;
var
expression
=
GetExpression
(
parentNode
);
if
(
expression
is
null
)
return
;
var
operation
=
context
.
SemanticModel
.
GetOperation
(
expression
,
c
ontext
.
C
ancellationToken
);
var
operation
=
context
.
SemanticModel
.
GetOperation
(
expression
,
cancellationToken
);
if
(
operation
is
null
)
return
;
...
...
src/Analyzers/CSharp/CodeFixes/CSharpCodeFixes.projitems
浏览文件 @
6716c84a
...
...
@@ -56,6 +56,7 @@
<Compile
Include=
"$(MSBuildThisFileDirectory)UseNullPropagation\CSharpUseNullPropagationCodeFixProvider.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UseObjectInitializer\CSharpUseObjectInitializerCodeFixProvider.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UseObjectInitializer\UseInitializerHelpers.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternCombinators\CSharpUsePatternCombinatorsCodeFixProvider.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternMatching\CSharpAsAndNullCheckCodeFixProvider.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UsePatternMatching\CSharpIsAndCastCheckCodeFixProvider.cs"
/>
<Compile
Include=
"$(MSBuildThisFileDirectory)UseSimpleUsingStatement\UseSimpleUsingStatementCodeFixProvider.cs"
/>
...
...
src/
Features/CSharp/Portable
/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
→
src/
Analyzers/CSharp/CodeFixes
/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
浏览文件 @
6716c84a
文件已移动
src/EditorFeatures/Test/Diagnostics/IDEDiagnosticIDConfigurationTests.cs
浏览文件 @
6716c84a
...
...
@@ -389,6 +389,9 @@ public void CSharp_VerifyIDEDiagnosticSeveritiesAreConfigurable()
# IDE0075
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
# IDE0076
csharp_style_prefer_pattern_matching = true:suggestion
# IDE1005
csharp_style_conditional_delegate_call = true:suggestion
...
...
@@ -895,6 +898,9 @@ public void CSharp_VerifyIDECodeStyleOptionsAreConfigurable()
# IDE0075, PreferSimplifiedBooleanExpressions
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
# IDE0076, PreferPatternMatching
csharp_style_prefer_pattern_matching = true:suggestion
# IDE1005, PreferConditionalDelegateCall
csharp_style_conditional_delegate_call = true:suggestion
...
...
src/VisualStudio/CSharp/Impl/CSharpVSResources.resx
浏览文件 @
6716c84a
...
...
@@ -483,6 +483,9 @@
<data
name=
"Prefer_conditional_delegate_call"
xml:space=
"preserve"
>
<value>
Prefer conditional delegate call
</value>
</data>
<data
name=
"Prefer_pattern_matching"
xml:space=
"preserve"
>
<value>
Prefer pattern matching
</value>
</data>
<data
name=
"Prefer_pattern_matching_over_is_with_cast_check"
xml:space=
"preserve"
>
<value>
Prefer pattern matching over 'is' with 'cast' check
</value>
</data>
...
...
src/VisualStudio/CSharp/Impl/Options/AutomationObject.cs
浏览文件 @
6716c84a
...
...
@@ -667,6 +667,12 @@ public string Style_PreferSwitchExpression
set
{
SetXmlOption
(
CSharpCodeStyleOptions
.
PreferSwitchExpression
,
value
);
}
}
public
string
Style_PreferPatternMatching
{
get
{
return
GetXmlOption
(
CSharpCodeStyleOptions
.
PreferPatternMatching
);
}
set
{
SetXmlOption
(
CSharpCodeStyleOptions
.
PreferPatternMatching
,
value
);
}
}
public
string
Style_PreferPatternMatchingOverAsWithNullCheck
{
get
{
return
GetXmlOption
(
CSharpCodeStyleOptions
.
PreferPatternMatchingOverAsWithNullCheck
);
}
...
...
src/VisualStudio/CSharp/Impl/Options/Formatting/StyleViewModel.cs
浏览文件 @
6716c84a
...
...
@@ -335,7 +335,7 @@ void M2(object o)
private
static
readonly
string
s_preferSwitchExpression
=
$@"
class C
{{
void
M1
()
int
M1
()
{{
//[
// {ServicesVSResources.Prefer_colon}
...
...
@@ -346,7 +346,7 @@ void M1()
}}
//]
}}
void
M2
()
int
M2
()
{{
//[
// {ServicesVSResources.Over_colon}
...
...
@@ -360,6 +360,26 @@ void M2()
//]
}}
}}
"
;
private
static
readonly
string
s_preferPatternMatching
=
$@"
class C
{{
bool
M1
()
{{
//[
// {ServicesVSResources.Prefer_colon}
return
num
is
1
or
2
;
//]
}}
bool
M2
()
{{
//[
// {ServicesVSResources.Over_colon}
return
num
==
1
||
num
==
2
;
//]
}}
}}
"
;
private
static
readonly
string
s_preferPatternMatchingOverAsWithNullCheck
=
$@"
...
...
@@ -1686,6 +1706,7 @@ internal StyleViewModel(OptionStore optionStore, IServiceProvider serviceProvide
CodeStyleItems
.
Add
(
new
BooleanCodeStyleOptionViewModel
(
CodeStyleOptions2
.
PreferCollectionInitializer
,
ServicesVSResources
.
Prefer_collection_initializer
,
s_preferCollectionInitializer
,
s_preferCollectionInitializer
,
this
,
optionStore
,
expressionPreferencesGroupTitle
));
CodeStyleItems
.
Add
(
new
BooleanCodeStyleOptionViewModel
(
CodeStyleOptions2
.
PreferSimplifiedBooleanExpressions
,
ServicesVSResources
.
Prefer_simplified_boolean_expressions
,
s_preferSimplifiedConditionalExpression
,
s_preferSimplifiedConditionalExpression
,
this
,
optionStore
,
expressionPreferencesGroupTitle
));
CodeStyleItems
.
Add
(
new
BooleanCodeStyleOptionViewModel
(
CSharpCodeStyleOptions
.
PreferSwitchExpression
,
CSharpVSResources
.
Prefer_switch_expression
,
s_preferSwitchExpression
,
s_preferSwitchExpression
,
this
,
optionStore
,
expressionPreferencesGroupTitle
));
CodeStyleItems
.
Add
(
new
BooleanCodeStyleOptionViewModel
(
CSharpCodeStyleOptions
.
PreferPatternMatching
,
CSharpVSResources
.
Prefer_pattern_matching
,
s_preferPatternMatching
,
s_preferPatternMatching
,
this
,
optionStore
,
expressionPreferencesGroupTitle
));
CodeStyleItems
.
Add
(
new
BooleanCodeStyleOptionViewModel
(
CSharpCodeStyleOptions
.
PreferPatternMatchingOverIsWithCastCheck
,
CSharpVSResources
.
Prefer_pattern_matching_over_is_with_cast_check
,
s_preferPatternMatchingOverIsWithCastCheck
,
s_preferPatternMatchingOverIsWithCastCheck
,
this
,
optionStore
,
expressionPreferencesGroupTitle
));
CodeStyleItems
.
Add
(
new
BooleanCodeStyleOptionViewModel
(
CSharpCodeStyleOptions
.
PreferPatternMatchingOverAsWithNullCheck
,
CSharpVSResources
.
Prefer_pattern_matching_over_as_with_null_check
,
s_preferPatternMatchingOverAsWithNullCheck
,
s_preferPatternMatchingOverAsWithNullCheck
,
this
,
optionStore
,
expressionPreferencesGroupTitle
));
CodeStyleItems
.
Add
(
new
BooleanCodeStyleOptionViewModel
(
CodeStyleOptions2
.
PreferConditionalExpressionOverAssignment
,
ServicesVSResources
.
Prefer_conditional_expression_over_if_with_assignments
,
s_preferConditionalExpressionOverIfWithAssignments
,
s_preferConditionalExpressionOverIfWithAssignments
,
this
,
optionStore
,
expressionPreferencesGroupTitle
));
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/CodeStyle/CSharpCodeStyleOptions.cs
浏览文件 @
6716c84a
...
...
@@ -57,6 +57,13 @@ private static Option2<T> CreateOption<T>(OptionGroup group, string name, T defa
EditorConfigStorageLocation
.
ForBoolCodeStyleOption
(
"csharp_style_prefer_switch_expression"
),
new
RoamingProfileStorageLocation
(
$"TextEditor.CSharp.Specific.
{
nameof
(
PreferSwitchExpression
)}
"
)});
public
static
readonly
Option2
<
CodeStyleOption2
<
bool
>>
PreferPatternMatching
=
CreateOption
(
CSharpCodeStyleOptionGroups
.
PatternMatching
,
nameof
(
PreferPatternMatching
),
defaultValue
:
s_trueWithSuggestionEnforcement
,
storageLocations
:
new
OptionStorageLocation2
[]
{
EditorConfigStorageLocation
.
ForBoolCodeStyleOption
(
"csharp_style_prefer_pattern_matching"
),
new
RoamingProfileStorageLocation
(
$"TextEditor.CSharp.Specific.
{
nameof
(
PreferPatternMatching
)}
"
)});
public
static
readonly
Option2
<
CodeStyleOption2
<
bool
>>
PreferPatternMatchingOverAsWithNullCheck
=
CreateOption
(
CSharpCodeStyleOptionGroups
.
PatternMatching
,
nameof
(
PreferPatternMatchingOverAsWithNullCheck
),
defaultValue
:
s_trueWithSuggestionEnforcement
,
...
...
@@ -307,6 +314,7 @@ public static IEnumerable<Option2<CodeStyleOption2<bool>>> GetCodeStyleOptions()
yield
return
VarElsewhere
;
yield
return
PreferConditionalDelegateCall
;
yield
return
PreferSwitchExpression
;
yield
return
PreferPatternMatching
;
yield
return
PreferPatternMatchingOverAsWithNullCheck
;
yield
return
PreferPatternMatchingOverIsWithCastCheck
;
yield
return
PreferSimpleDefaultExpression
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录