Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a7333f67
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,发现更多精彩内容 >>
提交
a7333f67
编写于
6月 18, 2020
作者:
A
Alireza Habibi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correctly rewrite default literals in patterns
上级
a9dc747c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
26 deletion
+45
-26
src/Analyzers/CSharp/Analyzers/UsePatternCombinators/CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs
...binators/CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs
+1
-1
src/EditorFeatures/CSharpTest/UsePatternCombinators/CSharpUsePatternCombinatorsDiagnosticAnalyzerTests.cs
...ors/CSharpUsePatternCombinatorsDiagnosticAnalyzerTests.cs
+27
-24
src/Features/CSharp/Portable/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
...Combinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
+17
-1
未找到文件。
src/Analyzers/CSharp/Analyzers/UsePatternCombinators/CSharpUsePatternCombinatorsDiagnosticAnalyzer.cs
浏览文件 @
a7333f67
...
...
@@ -56,7 +56,7 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
return
;
var
semanticModel
=
context
.
SemanticModel
;
var
expressionTypeOpt
=
context
.
Compilation
!
.
GetTypeByMetadataName
(
"System.Linq.Expressions.Expression`1"
);
var
expressionTypeOpt
=
semanticModel
.
Compilation
.
GetTypeByMetadataName
(
"System.Linq.Expressions.Expression`1"
);
if
(
expression
.
IsInExpressionTree
(
semanticModel
,
expressionTypeOpt
,
cancellationToken
))
return
;
...
...
src/EditorFeatures/CSharpTest/UsePatternCombinators/CSharpUsePatternCombinatorsDiagnosticAnalyzerTests.cs
浏览文件 @
a7333f67
...
...
@@ -50,29 +50,32 @@ private static string FromExpression(string expression)
using System.Collections.Generic;
class C
{
bool field = {|FixAllInDocument:EXPRESSION|};
bool Method() => EXPRESSION;
bool Prop1 => EXPRESSION;
bool Prop2 { get } = EXPRESSION;
void If() { if (EXPRESSION) ; }
void Argument1() => Test(EXPRESSION);
void Argument2() => Test(() => EXPRESSION);
void Argument3() => Test(_ => EXPRESSION);
void For() { for (; EXPRESSION; ); }
void Local() { var local = EXPRESSION; }
void Conditional() { _ = EXPRESSION ? EXPRESSION : EXPRESSION; }
void Assignment() { _ = EXPRESSION; }
void Do() { do ; while (EXPRESSION); }
void While() { while (EXPRESSION) ; }
bool When() => o switch { _ when EXPRESSION => EXPRESSION };
bool Return() { return EXPRESSION; }
IEnumerable<bool> YieldReturn() { yield return EXPRESSION; }
Func<object, bool> SimpleLambda() => o => EXPRESSION;
Func<bool> ParenthesizedLambda() => () => EXPRESSION;
void LocalFunc() { bool LocalFunction() => EXPRESSION; }
int i;
int? nullable;
object o;
static bool field = {|FixAllInDocument:EXPRESSION|};
static bool Method() => EXPRESSION;
static bool Prop1 => EXPRESSION;
static bool Prop2 { get; } = EXPRESSION;
static void If() { if (EXPRESSION) ; }
static void Argument1() => Test(EXPRESSION);
static void Argument2() => Test(() => EXPRESSION);
static void Argument3() => Test(_ => EXPRESSION);
static void Test(bool b) {}
static void Test(Func<bool> b) {}
static void Test(Func<object, bool> b) {}
static void For() { for (; EXPRESSION; ); }
static void Local() { var local = EXPRESSION; }
static void Conditional() { _ = EXPRESSION ? EXPRESSION : EXPRESSION; }
static void Assignment() { _ = EXPRESSION; }
static void Do() { do ; while (EXPRESSION); }
static void While() { while (EXPRESSION) ; }
static bool When() => o switch { _ when EXPRESSION => EXPRESSION };
static bool Return() { return EXPRESSION; }
static IEnumerable<bool> YieldReturn() { yield return EXPRESSION; }
static Func<object, bool> SimpleLambda() => o => EXPRESSION;
static Func<bool> ParenthesizedLambda() => () => EXPRESSION;
static void LocalFunc() { bool LocalFunction() => EXPRESSION; }
static int i;
static int? nullable;
static object o;
}
"
;
return
initialMarkup
.
Replace
(
"EXPRESSION"
,
expression
);
...
...
@@ -85,13 +88,13 @@ class C
[
InlineData
(
"o != null"
)]
[
InlineData
(
"!(o is null)"
)]
[
InlineData
(
"o is int ii || o is long jj"
)]
[
InlineData
(
"i == default || i > default(int)"
)]
[
Theory
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUsePatternCombinators
)]
public
async
Task
TestMissingOnExpression
(
string
expression
)
{
await
TestAllMissingOnExpressionAsync
(
expression
);
}
[
InlineData
(
"i == default || i > default(int)"
,
"i is default(int) or > (default(int))"
)]
[
InlineData
(
"!(o is C c)"
,
"o is not C c"
)]
[
InlineData
(
"o is int ii && o is long jj"
,
"o is int ii and long jj"
)]
[
InlineData
(
"!(o is C)"
,
"o is not C"
)]
...
...
src/Features/CSharp/Portable/UsePatternCombinators/CSharpUsePatternCombinatorsCodeFixProvider.cs
浏览文件 @
a7333f67
...
...
@@ -89,7 +89,7 @@ private static PatternSyntax AsPatternSyntax(AnalyzedPattern pattern)
Token
(
p
.
Token
.
LeadingTrivia
,
p
.
IsDisjunctive
?
SyntaxKind
.
OrKeyword
:
SyntaxKind
.
AndKeyword
,
TriviaList
(
p
.
Token
.
GetAllTrailingTrivia
())),
AsPatternSyntax
(
p
.
Right
).
Parenthesize
()),
Constant
p
=>
ConstantPattern
(
p
.
ExpressionSyntax
.
Parenthesize
(
)),
Constant
p
=>
ConstantPattern
(
AsExpressionSyntax
(
p
)),
Source
p
=>
p
.
PatternSyntax
,
Type
p
=>
TypePattern
(
p
.
TypeSyntax
),
Relational
p
=>
RelationalPattern
(
Token
(
MapToSyntaxKind
(
p
.
OperatorKind
)),
p
.
Value
.
Parenthesize
()),
...
...
@@ -98,6 +98,22 @@ private static PatternSyntax AsPatternSyntax(AnalyzedPattern pattern)
};
}
private
static
ExpressionSyntax
AsExpressionSyntax
(
Constant
constant
)
{
var
expr
=
constant
.
ExpressionSyntax
;
if
(
expr
.
IsKind
(
SyntaxKind
.
DefaultLiteralExpression
))
{
// default literals are not permitted in patterns
var
convertedType
=
constant
.
Target
.
SemanticModel
.
GetTypeInfo
(
expr
).
ConvertedType
;
if
(
convertedType
!=
null
)
{
return
DefaultExpression
(
convertedType
.
GenerateTypeSyntax
());
}
}
return
expr
.
Parenthesize
();
}
private
class
MyCodeAction
:
CodeAction
.
DocumentChangeAction
{
public
MyCodeAction
(
Func
<
CancellationToken
,
Task
<
Document
>>
createChangedDocument
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录