Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
02c58e02
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,发现更多精彩内容 >>
提交
02c58e02
编写于
5月 14, 2020
作者:
C
Cyrus Najmabadi
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test for nested type
上级
6c8c3a04
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
81 addition
and
6 deletion
+81
-6
src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs
...orFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs
+74
-0
src/Features/CSharp/Portable/MetadataAsSource/CSharpMetadataAsSourceService.cs
...ortable/MetadataAsSource/CSharpMetadataAsSourceService.cs
+7
-6
未找到文件。
src/EditorFeatures/Test/MetadataAsSource/MetadataAsSourceTests.cs
浏览文件 @
02c58e02
...
...
@@ -2970,6 +2970,80 @@ public class TestType
context
.
VerifyResult
(
metadataAsSourceFile
,
expected
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MetadataAsSource
)]
public
async
Task
TestNullableEnableDisable13
()
{
var
metadata
=
@"
#nullable enable
using System;
public class TestType
{
public void M1(string s)
{
}
#nullable disable
public class Nested
{
public void NestedM(string s)
{
}
}
#nullable enable
public void M2(string s)
{
}
}"
;
var
sourceWithSymbolReference
=
@"
class C
{
void M()
{
var obj = new TestType().[|M1|](null);
}
}"
;
var
expected
=
$@"#region
{
FeaturesResources
.
Assembly
}
ReferencedAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
//
{
CodeAnalysisResources
.
InMemoryAssembly
}
#endregion
#nullable enable
public class TestType
{{
public
TestType
();
public
void
[|
M1
|](
string
s
);
public
void
M2
(
string
s
);
public
class
Nested
{{
public
Nested
();
#
nullable
disable
public
void
NestedM
(
string
s
);
#
nullable
enable
}}
}}
"
;
using
var
context
=
TestContext
.
Create
(
LanguageNames
.
CSharp
,
SpecializedCollections
.
SingletonEnumerable
(
metadata
),
includeXmlDocComments
:
false
,
languageVersion
:
"CSharp8"
,
sourceWithSymbolReference
:
sourceWithSymbolReference
,
metadataLanguageVersion
:
"CSharp8"
);
var
navigationSymbol
=
await
context
.
GetNavigationSymbolAsync
();
var
metadataAsSourceFile
=
await
context
.
GenerateSourceAsync
(
navigationSymbol
);
context
.
VerifyResult
(
metadataAsSourceFile
,
expected
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
MetadataAsSource
)]
public
async
Task
TestDynamic1
()
{
...
...
src/Features/CSharp/Portable/MetadataAsSource/CSharpMetadataAsSourceService.cs
浏览文件 @
02c58e02
...
...
@@ -143,13 +143,14 @@ private static SyntaxTrivia[] CreateNullableTrivia(bool enable)
};
}
private
SyntaxNode
AddNullableRegions
(
SyntaxNode
node
,
CancellationToken
cancellationToken
)
private
TSyntax
AddNullableRegions
<
TSyntax
>(
TSyntax
node
,
CancellationToken
cancellationToken
)
where
TSyntax
:
SyntaxNode
{
return
node
switch
{
CompilationUnitSyntax
compilationUnit
=>
compilationUnit
.
WithMembers
(
AddNullableRegions
(
compilationUnit
.
Members
,
cancellationToken
)),
NamespaceDeclarationSyntax
ns
=>
ns
.
WithMembers
(
AddNullableRegions
(
ns
.
Members
,
cancellationToken
)),
TypeDeclarationSyntax
type
=>
AddNullableRegionsAroundTypeMembers
(
type
,
cancellationToken
),
CompilationUnitSyntax
compilationUnit
=>
(
TSyntax
)(
object
)
compilationUnit
.
WithMembers
(
AddNullableRegions
(
compilationUnit
.
Members
,
cancellationToken
)),
NamespaceDeclarationSyntax
ns
=>
(
TSyntax
)(
object
)
ns
.
WithMembers
(
AddNullableRegions
(
ns
.
Members
,
cancellationToken
)),
TypeDeclarationSyntax
type
=>
(
TSyntax
)(
object
)
AddNullableRegionsAroundTypeMembers
(
type
,
cancellationToken
),
_
=>
node
,
};
}
...
...
@@ -161,7 +162,7 @@ private SyntaxNode AddNullableRegions(SyntaxNode node, CancellationToken cancell
using
var
_
=
ArrayBuilder
<
MemberDeclarationSyntax
>.
GetInstance
(
out
var
builder
);
foreach
(
var
member
in
members
)
builder
.
Add
(
(
MemberDeclarationSyntax
)
AddNullableRegions
(
member
,
cancellationToken
));
builder
.
Add
(
AddNullableRegions
(
member
,
cancellationToken
));
return
SyntaxFactory
.
List
(
builder
);
}
...
...
@@ -181,7 +182,7 @@ private SyntaxNode AddNullableRegions(SyntaxNode node, CancellationToken cancell
{
// if we hit a type, and we're currently disabled, then switch us back to enabled for that type.
// This ensures whenever we walk into a type-decl, we're always in the enabled-state.
builder
.
Add
(
TransitionTo
(
member
,
enabled
:
true
,
ref
currentlyEnabled
));
builder
.
Add
(
TransitionTo
(
AddNullableRegions
(
member
,
cancellationToken
)
,
enabled
:
true
,
ref
currentlyEnabled
));
continue
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录