Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
c8840765
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,发现更多精彩内容 >>
提交
c8840765
编写于
3月 21, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Do not offer to use ?. when in an query that will become an expression tree.
上级
423c52f2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
165 addition
and
3 deletion
+165
-3
src/Analyzers/CSharp/Tests/UseNullPropagation/UseNullPropagationTests.cs
...Sharp/Tests/UseNullPropagation/UseNullPropagationTests.cs
+59
-0
src/Analyzers/VisualBasic/Tests/UseNullPropagation/UseNullPropagationTests.vb
...Basic/Tests/UseNullPropagation/UseNullPropagationTests.vb
+52
-0
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs
...nsions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs
+36
-1
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Extensions/SyntaxNodeExtensions.vb
...s/Compiler/VisualBasic/Extensions/SyntaxNodeExtensions.vb
+18
-2
未找到文件。
src/Analyzers/CSharp/Tests/UseNullPropagation/UseNullPropagationTests.cs
浏览文件 @
c8840765
...
...
@@ -412,6 +412,65 @@ public void Method<T>(Expression<Func<T, string>> functor)
}"
);
}
[
WorkItem
(
33992
,
"https://github.com/dotnet/roslyn/issues/33992"
)]
[
WorkItem
(
17623
,
"https://github.com/dotnet/roslyn/issues/17623"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseNullPropagation
)]
public
async
Task
TestInExpressionTree2
()
{
await
TestMissingInRegularAndScriptAsync
(
@"
using System.Linq;
class C
{
void Main()
{
_ = from item in Enumerable.Empty<(int? x, int? y)?>().AsQueryable()
select [||]item == null ? null : item.Value.x;
}
}"
);
}
[
WorkItem
(
33992
,
"https://github.com/dotnet/roslyn/issues/33992"
)]
[
WorkItem
(
17623
,
"https://github.com/dotnet/roslyn/issues/17623"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseNullPropagation
)]
public
async
Task
TestInExpressionTree3
()
{
await
TestMissingInRegularAndScriptAsync
(
@"
using System.Linq;
class C
{
void Main()
{
_ = from item in Enumerable.Empty<(int? x, int? y)?>().AsQueryable()
where ([||]item == null ? null : item.Value.x) > 0
select item;
}
}"
);
}
[
WorkItem
(
33992
,
"https://github.com/dotnet/roslyn/issues/33992"
)]
[
WorkItem
(
17623
,
"https://github.com/dotnet/roslyn/issues/17623"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseNullPropagation
)]
public
async
Task
TestInExpressionTree4
()
{
await
TestMissingInRegularAndScriptAsync
(
@"
using System.Linq;
class C
{
void Main()
{
_ = from item in Enumerable.Empty<(int? x, int? y)?>().AsQueryable()
let x = [||]item == null ? null : item.Value.x
select x;
}
}"
);
}
[
WorkItem
(
19774
,
"https://github.com/dotnet/roslyn/issues/19774"
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseNullPropagation
)]
public
async
Task
TestNullableMemberAccess
()
...
...
src/Analyzers/VisualBasic/Tests/UseNullPropagation/UseNullPropagationTests.vb
浏览文件 @
c8840765
...
...
@@ -715,5 +715,57 @@ Class C
End Class"
)
End
Function
<
WorkItem
(
33992
,
"https://github.com/dotnet/roslyn/issues/33992"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseNullPropagation
)
>
Public
Async
Function
TestExpressionTree1
()
As
Task
Await
TestMissingInRegularAndScriptAsync
(
"
Imports System
Imports System.Linq
Public Class Class1
Public Sub Foo()
Dim q = From item In Enumerable.Empty(Of (x As Integer?, y As Integer?)?)().AsQueryable()
Select [||]If(item Is Nothing, Nothing, item.Value.x)
End Sub
End Class"
)
End
Function
<
WorkItem
(
33992
,
"https://github.com/dotnet/roslyn/issues/33992"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseNullPropagation
)
>
Public
Async
Function
TestExpressionTree2
()
As
Task
Await
TestMissingInRegularAndScriptAsync
(
"
Imports System
Imports System.Linq
Public Class Class1
Public Sub Foo()
Dim q = From item In Enumerable.Empty(Of (x As Integer?, y As Integer?)?)().AsQueryable()
Where [||]If(item Is Nothing, Nothing, item.Value.x) > 0
Select item
End Sub
End Class"
)
End
Function
<
WorkItem
(
33992
,
"https://github.com/dotnet/roslyn/issues/33992"
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsUseNullPropagation
)
>
Public
Async
Function
TestExpressionTree3
()
As
Task
Await
TestMissingInRegularAndScriptAsync
(
"
Imports System
Imports System.Linq
Public Class Class1
Public Sub Foo()
Dim q = From item In Enumerable.Empty(Of (x As Integer?, y As Integer?)?)().AsQueryable()
Let x = [||]If(item Is Nothing, Nothing, item.Value.x)
Select x
End Sub
End Class"
)
End
Function
End
Class
End
Namespace
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/CSharp/Extensions/SyntaxNodeExtensions.cs
浏览文件 @
c8840765
...
...
@@ -11,6 +11,7 @@
using
System.Diagnostics.CodeAnalysis
;
using
System.Linq
;
using
System.Threading
;
using
Microsoft.CodeAnalysis
;
using
Microsoft.CodeAnalysis.CSharp.LanguageServices
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Microsoft.CodeAnalysis.Shared.Extensions
;
...
...
@@ -906,7 +907,7 @@ public static bool ContainsInArgument(this ConstructorInitializerSyntax initiali
return
false
;
}
return
initializer
.
ArgumentList
.
Arguments
.
Any
(
a
=>
a
.
Span
.
Contains
(
textSpan
));
return
initializer
.
ArgumentList
.
Arguments
.
Any
<
ArgumentSyntax
>
(
a
=>
a
.
Span
.
Contains
(
textSpan
));
}
public
static
bool
ContainsInBlockBody
(
this
BlockSyntax
block
,
TextSpan
textSpan
)
...
...
@@ -962,6 +963,25 @@ public static IEnumerable<MemberDeclarationSyntax> GetMembers(this SyntaxNode no
{
var
typeInfo
=
semanticModel
.
GetTypeInfo
(
current
,
cancellationToken
);
if
(
expressionTypeOpt
.
Equals
(
typeInfo
.
ConvertedType
?.
OriginalDefinition
))
return
true
;
}
else
if
(
current
is
SelectOrGroupClauseSyntax
clause
)
{
var
info
=
semanticModel
.
GetSymbolInfo
(
clause
,
cancellationToken
);
if
(
TakesExpressionTree
(
info
,
expressionTypeOpt
))
return
true
;
}
else
if
(
current
is
OrderingSyntax
ordering
)
{
var
info
=
semanticModel
.
GetSymbolInfo
(
ordering
,
cancellationToken
);
if
(
TakesExpressionTree
(
info
,
expressionTypeOpt
))
return
true
;
}
else
if
(
current
is
QueryClauseSyntax
queryClause
)
{
var
info
=
semanticModel
.
GetQueryClauseInfo
(
queryClause
,
cancellationToken
);
if
(
TakesExpressionTree
(
info
.
CastInfo
,
expressionTypeOpt
)
||
TakesExpressionTree
(
info
.
OperationInfo
,
expressionTypeOpt
))
{
return
true
;
}
...
...
@@ -970,6 +990,21 @@ public static IEnumerable<MemberDeclarationSyntax> GetMembers(this SyntaxNode no
}
return
false
;
static
bool
TakesExpressionTree
(
SymbolInfo
info
,
INamedTypeSymbol
expressionType
)
{
foreach
(
var
symbol
in
info
.
GetAllSymbols
())
{
if
(
symbol
is
IMethodSymbol
method
&&
method
.
Parameters
.
Length
>
0
&&
expressionType
.
Equals
(
method
.
Parameters
[
0
].
Type
?.
OriginalDefinition
))
{
return
true
;
}
}
return
false
;
}
}
public
static
bool
IsInDeconstructionLeft
(
...
...
src/Workspaces/SharedUtilitiesAndExtensions/Compiler/VisualBasic/Extensions/SyntaxNodeExtensions.vb
浏览文件 @
c8840765
...
...
@@ -1052,10 +1052,26 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
While
current
IsNot
Nothing
If
SyntaxFacts
.
IsSingleLineLambdaExpression
(
current
.
Kind
)
OrElse
SyntaxFacts
.
IsMultiLineLambdaExpression
(
current
.
Kind
)
Then
Dim
T
ypeInfo
=
semanticModel
.
GetTypeInfo
(
current
,
cancellationToken
)
If
expressionTypeOpt
.
Equals
(
T
ypeInfo
.
ConvertedType
?
.
OriginalDefinition
)
Then
Dim
t
ypeInfo
=
semanticModel
.
GetTypeInfo
(
current
,
cancellationToken
)
If
expressionTypeOpt
.
Equals
(
t
ypeInfo
.
ConvertedType
?
.
OriginalDefinition
)
Then
Return
True
End
If
ElseIf
TypeOf
current
Is
OrderingSyntax
OrElse
TypeOf
current
Is
QueryClauseSyntax
OrElse
TypeOf
current
Is
FunctionAggregationSyntax
OrElse
TypeOf
current
Is
ExpressionRangeVariableSyntax
Then
Dim
info
=
semanticModel
.
GetSymbolInfo
(
current
,
cancellationToken
)
For
Each
symbol
In
info
.
GetAllSymbols
()
Dim
method
=
TryCast
(
symbol
,
IMethodSymbol
)
If
method
IsNot
Nothing
AndAlso
method
.
Parameters
.
Length
>
0
AndAlso
expressionTypeOpt
.
Equals
(
method
.
Parameters
(
0
).
Type
.
OriginalDefinition
)
Then
Return
True
End
If
Next
End
If
current
=
current
.
Parent
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录