Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
17d363eb
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,发现更多精彩内容 >>
提交
17d363eb
编写于
5月 05, 2015
作者:
J
Jonathon Marolf
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Generate types with the correct accessibility if they are part of public fields
fixes internal issue #1107929
上级
d61d8fda
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
88 addition
and
0 deletion
+88
-0
src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs
.../CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs
+31
-0
src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateType/GenerateTypeTests.vb
...alBasicTest/Diagnostics/GenerateType/GenerateTypeTests.vb
+28
-0
src/Workspaces/CSharp/Portable/Extensions/ISemanticModelExtensions.cs
...es/CSharp/Portable/Extensions/ISemanticModelExtensions.cs
+12
-0
src/Workspaces/VisualBasic/Portable/Extensions/ISemanticModelExtensions.vb
...sualBasic/Portable/Extensions/ISemanticModelExtensions.vb
+17
-0
未找到文件。
src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs
浏览文件 @
17d363eb
...
...
@@ -1951,5 +1951,36 @@ public void TestWithUsingStatic2()
{
TestMissing
(
@"using [|Sample|] ; "
);
}
[
WorkItem
(
1107929
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)]
public
void
TestAccesiblityForPublicFields
()
{
Test
(
@"class A { public B b = new [|B|](); }"
,
@"public class B { public B() { } }"
,
index
:
0
,
isAddedDocument
:
true
);
}
[
WorkItem
(
1107929
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)]
public
void
TestAccesiblityForPublicFields2
()
{
Test
(
@"class A { public B b = new [|B|](); }"
,
@"class A { public B b = new B(); } public class B { public B() {}}"
,
index
:
1
);
}
[
WorkItem
(
1107929
)]
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)]
public
void
TestAccesiblityForPublicFields3
()
{
Test
(
@"class A { public B b = new [|B|](); }"
,
@"class A { public B b = new B(); public class B { public B() {}}}"
,
index
:
2
);
}
}
}
src/EditorFeatures/VisualBasicTest/Diagnostics/GenerateType/GenerateTypeTests.vb
浏览文件 @
17d363eb
...
...
@@ -747,6 +747,34 @@ NewLines("Public Interface I \n Sub Foo(a As X.Y.Z) \n End Interface \n Public
index
:
=
0
)
End
Sub
<
WorkItem
(
1107929
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)
>
Public
Sub
TestAccesiblityForPublicFields
()
Test
(
NewLines
(
"Public Class A \n Public B As New [|B|]() \n End Class"
),
NewLines
(
"Public Class B \n Public Sub New() \n End Sub \n End Class"
),
index
:
=
0
,
isAddedDocument
:
=
True
)
End
Sub
<
WorkItem
(
1107929
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)
>
Public
Sub
TestAccesiblityForPublicFields2
()
Test
(
NewLines
(
"Public Class A \n Public B As New [|B|]() \n End Class"
),
NewLines
(
"Public Class A \n Public B As New B() \n End Class \n\n Public Class B \n Public Sub New() \n End Sub \n End Class"
),
index
:
=
1
)
End
Sub
<
WorkItem
(
1107929
)
>
<
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
CodeActionsGenerateType
)
>
Public
Sub
TestAccesiblityForPublicFields3
()
Test
(
NewLines
(
"Public Class A \n Public B As New [|B|]() \n End Class"
),
NewLines
(
"Public Class A \n Public B As New B() \n Public Class B \n Public Sub New() \n End Sub \n End Class \n End Class"
),
index
:
=
2
)
End
Sub
Public
Class
AddImportTestsWithAddImportDiagnosticProvider
Inherits
AbstractVisualBasicDiagnosticProviderBasedUserDiagnosticTest
...
...
src/Workspaces/CSharp/Portable/Extensions/ISemanticModelExtensions.cs
浏览文件 @
17d363eb
...
...
@@ -366,6 +366,18 @@ public static ISet<INamespaceSymbol> GetUsingNamespacesInScope(this SemanticMode
variableDeclaration
.
Variables
[
0
],
cancellationToken
)).
DeclaredAccessibility
;
}
// Also do the same check if we are in an object creation expression
if
(
type
.
IsParentKind
(
SyntaxKind
.
ObjectCreationExpression
)
&&
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
EqualsValueClause
)
&&
type
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
VariableDeclarator
)
&&
type
.
Parent
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
VariableDeclaration
)
&&
type
.
Parent
.
Parent
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
FieldDeclaration
))
{
var
variableDeclaration
=
(
VariableDeclarationSyntax
)
type
.
Parent
.
Parent
.
Parent
.
Parent
;
return
((
ISymbol
)
semanticModel
.
GetDeclaredSymbol
(
variableDeclaration
.
Variables
[
0
],
cancellationToken
)).
DeclaredAccessibility
;
}
// 3) The return type of a delegate type must be at least as accessible as the
// delegate type itself.
// 6) The return type of a method must be at least as accessible as the method
...
...
src/Workspaces/VisualBasic/Portable/Extensions/ISemanticModelExtensions.vb
浏览文件 @
17d363eb
...
...
@@ -233,6 +233,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
Return
containingType
.
DeclaredAccessibility
End
If
' Determine accessibility of field or event
' Public B as B
If
type
.
IsParentKind
(
SyntaxKind
.
SimpleAsClause
)
AndAlso
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
VariableDeclarator
)
Then
If
type
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
FieldDeclaration
)
OrElse
...
...
@@ -245,6 +247,21 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Extensions
End
If
End
If
' Determine accessibility of field or event
' Public B as New B()
If
type
.
IsParentKind
(
SyntaxKind
.
ObjectCreationExpression
)
AndAlso
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
AsNewClause
)
AndAlso
type
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
VariableDeclarator
)
Then
If
type
.
Parent
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
FieldDeclaration
)
OrElse
type
.
Parent
.
Parent
.
Parent
.
IsParentKind
(
SyntaxKind
.
EventStatement
)
Then
Dim
variableDeclarator
=
DirectCast
(
type
.
Parent
.
Parent
.
Parent
,
VariableDeclaratorSyntax
)
If
variableDeclarator
.
Names
.
Count
>
0
Then
Dim
variableDeclaration
=
semanticModel
.
GetDeclaredSymbol
(
variableDeclarator
.
Names
(
0
),
cancellationToken
)
Return
variableDeclaration
.
DeclaredAccessibility
End
If
End
If
End
If
If
type
.
IsParentKind
(
SyntaxKind
.
SimpleAsClause
)
Then
If
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
DelegateFunctionStatement
)
OrElse
type
.
Parent
.
IsParentKind
(
SyntaxKind
.
FunctionStatement
)
OrElse
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录