Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
6f87545a
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,发现更多精彩内容 >>
未验证
提交
6f87545a
编写于
6月 17, 2020
作者:
M
mizuniga
提交者:
GitHub
6月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Making name of script globals type hidden (#43425)
上级
697e6309
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
226 addition
and
5 deletion
+226
-5
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
...ompilers/CSharp/Portable/Compilation/CSharpCompilation.cs
+5
-2
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.cs
...ers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.cs
+16
-3
src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs
...rs/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs
+193
-0
src/Compilers/Core/Portable/Compilation/Compilation.cs
src/Compilers/Core/Portable/Compilation/Compilation.cs
+6
-0
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
...isualBasic/Portable/Compilation/VisualBasicCompilation.vb
+6
-0
未找到文件。
src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
浏览文件 @
6f87545a
...
@@ -58,6 +58,9 @@ public sealed partial class CSharpCompilation : Compilation
...
@@ -58,6 +58,9 @@ public sealed partial class CSharpCompilation : Compilation
private
readonly
Lazy
<
AliasSymbol
>
_globalNamespaceAlias
;
// alias symbol used to resolve "global::".
private
readonly
Lazy
<
AliasSymbol
>
_globalNamespaceAlias
;
// alias symbol used to resolve "global::".
private
readonly
Lazy
<
ImplicitNamedTypeSymbol
?>
_scriptClass
;
private
readonly
Lazy
<
ImplicitNamedTypeSymbol
?>
_scriptClass
;
// The type of host object model if available.
private
TypeSymbol
?
_lazyHostObjectTypeSymbol
;
// All imports (using directives and extern aliases) in syntax trees in this compilation.
// All imports (using directives and extern aliases) in syntax trees in this compilation.
// NOTE: We need to de-dup since the Imports objects that populate the list may be GC'd
// NOTE: We need to de-dup since the Imports objects that populate the list may be GC'd
// and re-created.
// and re-created.
...
@@ -1461,8 +1464,8 @@ private static CSDiagnosticInfo CreateReflectionTypeNotFoundError(Type type)
...
@@ -1461,8 +1464,8 @@ private static CSDiagnosticInfo CreateReflectionTypeNotFoundError(Type type)
);
);
}
}
// The type of host object model if available.
protected
override
ITypeSymbol
?
CommonScriptGlobalsType
private
TypeSymbol
?
_lazyHostObjectTypeSymbol
;
=>
GetHostObjectTypeSymbol
()?.
GetPublicSymbol
()
;
internal
TypeSymbol
?
GetHostObjectTypeSymbol
()
internal
TypeSymbol
?
GetHostObjectTypeSymbol
()
{
{
...
...
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.cs
浏览文件 @
6f87545a
...
@@ -367,9 +367,22 @@ private bool ShouldVisitNamespace(ISymbol containingSymbol)
...
@@ -367,9 +367,22 @@ private bool ShouldVisitNamespace(ISymbol containingSymbol)
private
bool
IncludeNamedType
(
INamedTypeSymbol
namedType
)
private
bool
IncludeNamedType
(
INamedTypeSymbol
namedType
)
{
{
return
if
(
namedType
is
null
)
namedType
!=
null
&&
{
(!
namedType
.
IsScriptClass
||
format
.
CompilerInternalOptions
.
IncludesOption
(
SymbolDisplayCompilerInternalOptions
.
IncludeScriptType
));
return
false
;
}
if
(
namedType
.
IsScriptClass
&&
!
format
.
CompilerInternalOptions
.
IncludesOption
(
SymbolDisplayCompilerInternalOptions
.
IncludeScriptType
))
{
return
false
;
}
if
(
namedType
==
semanticModelOpt
?.
Compilation
.
ScriptGlobalsType
)
{
return
false
;
}
return
true
;
}
}
private
static
bool
IsEnumMember
(
ISymbol
symbol
)
private
static
bool
IsEnumMember
(
ISymbol
symbol
)
...
...
src/Compilers/CSharp/Test/Symbol/SymbolDisplay/SymbolDisplayTests.cs
浏览文件 @
6f87545a
...
@@ -2530,6 +2530,199 @@ class C2 {} } } } }
...
@@ -2530,6 +2530,199 @@ class C2 {} } } } }
SymbolDisplayPartKind
.
NamespaceName
);
SymbolDisplayPartKind
.
NamespaceName
);
}
}
public
class
ScriptGlobals
{
public
void
Method
(
int
p
)
{
Event
.
Invoke
();
}
public
delegate
void
MyDelegate
(
int
x
);
public
int
Field
;
public
int
Property
=>
1
;
public
event
Action
Event
;
public
class
NestedType
{
public
void
Method
(
int
p
)
{
Event
.
Invoke
();
}
public
delegate
void
MyDelegate
(
int
x
);
public
int
Field
;
public
int
Property
=>
1
;
public
event
Action
Event
;
}
}
[
Fact
]
public
void
TestMembersInScriptGlobals
()
{
var
text
=
@"1"
;
var
tree
=
SyntaxFactory
.
ParseSyntaxTree
(
text
,
TestOptions
.
Script
);
var
hostReference
=
MetadataReference
.
CreateFromFile
(
typeof
(
ScriptGlobals
).
Assembly
.
Location
);
var
comp
=
CSharpCompilation
.
CreateScriptCompilation
(
"submission1"
,
tree
,
TargetFrameworkUtil
.
GetReferences
(
TargetFramework
.
Standard
).
Concat
(
hostReference
),
returnType
:
typeof
(
object
),
globalsType
:
typeof
(
ScriptGlobals
));
var
model
=
comp
.
GetSemanticModel
(
tree
);
var
hostTypeSymbol
=
comp
.
GetHostObjectTypeSymbol
();
var
methodSymbol
=
hostTypeSymbol
.
GetMember
(
"Method"
);
var
delegateSymbol
=
hostTypeSymbol
.
GetMember
(
"MyDelegate"
);
var
fieldSymbol
=
hostTypeSymbol
.
GetMember
(
"Field"
);
var
propertySymbol
=
hostTypeSymbol
.
GetMember
(
"Property"
);
var
eventSymbol
=
hostTypeSymbol
.
GetMember
(
"Event"
);
var
nestedTypeSymbol
=
(
TypeSymbol
)
hostTypeSymbol
.
GetMember
(
"NestedType"
);
var
nestedMethodSymbol
=
nestedTypeSymbol
.
GetMember
(
"Method"
);
var
nestedDelegateSymbol
=
nestedTypeSymbol
.
GetMember
(
"MyDelegate"
);
var
nestedFieldSymbol
=
nestedTypeSymbol
.
GetMember
(
"Field"
);
var
nestedPropertySymbol
=
nestedTypeSymbol
.
GetMember
(
"Property"
);
var
nestedEventSymbol
=
nestedTypeSymbol
.
GetMember
(
"Event"
);
Verify
(
methodSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"void Method(int p)"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
MethodName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ParameterName
,
SymbolDisplayPartKind
.
Punctuation
);
Verify
(
delegateSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"MyDelegate(int x)"
,
SymbolDisplayPartKind
.
DelegateName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ParameterName
,
SymbolDisplayPartKind
.
Punctuation
);
Verify
(
fieldSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"int Field"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
FieldName
);
Verify
(
propertySymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"int Property { get; }"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
PropertyName
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
Punctuation
);
Verify
(
eventSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"event System.Action Event"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
NamespaceName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
DelegateName
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
EventName
);
Verify
(
nestedTypeSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"NestedType"
,
SymbolDisplayPartKind
.
ClassName
);
Verify
(
nestedMethodSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"void NestedType.Method(int p)"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ClassName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
MethodName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ParameterName
,
SymbolDisplayPartKind
.
Punctuation
);
Verify
(
nestedDelegateSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"NestedType.MyDelegate(int x)"
,
SymbolDisplayPartKind
.
ClassName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
DelegateName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ParameterName
,
SymbolDisplayPartKind
.
Punctuation
);
Verify
(
nestedFieldSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"int NestedType.Field"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ClassName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
FieldName
);
Verify
(
nestedPropertySymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"int NestedType.Property { get; }"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ClassName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
PropertyName
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
Punctuation
);
Verify
(
nestedEventSymbol
.
ToMinimalDisplayParts
(
model
,
position
:
0
,
s_memberSignatureDisplayFormat
),
"event System.Action NestedType.Event"
,
SymbolDisplayPartKind
.
Keyword
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
NamespaceName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
DelegateName
,
SymbolDisplayPartKind
.
Space
,
SymbolDisplayPartKind
.
ClassName
,
SymbolDisplayPartKind
.
Punctuation
,
SymbolDisplayPartKind
.
EventName
);
}
private
static
readonly
SymbolDisplayFormat
s_memberSignatureDisplayFormat
=
new
SymbolDisplayFormat
(
globalNamespaceStyle
:
SymbolDisplayGlobalNamespaceStyle
.
Omitted
,
genericsOptions
:
SymbolDisplayGenericsOptions
.
IncludeTypeParameters
|
SymbolDisplayGenericsOptions
.
IncludeTypeConstraints
,
memberOptions
:
SymbolDisplayMemberOptions
.
IncludeRef
|
SymbolDisplayMemberOptions
.
IncludeType
|
SymbolDisplayMemberOptions
.
IncludeParameters
|
SymbolDisplayMemberOptions
.
IncludeContainingType
,
delegateStyle
:
SymbolDisplayDelegateStyle
.
NameAndSignature
,
kindOptions
:
SymbolDisplayKindOptions
.
IncludeMemberKeyword
,
propertyStyle
:
SymbolDisplayPropertyStyle
.
ShowReadWriteDescriptor
,
parameterOptions
:
SymbolDisplayParameterOptions
.
IncludeName
|
SymbolDisplayParameterOptions
.
IncludeType
|
SymbolDisplayParameterOptions
.
IncludeParamsRefOut
|
SymbolDisplayParameterOptions
.
IncludeExtensionThis
|
SymbolDisplayParameterOptions
.
IncludeDefaultValue
|
SymbolDisplayParameterOptions
.
IncludeOptionalBrackets
,
localOptions
:
SymbolDisplayLocalOptions
.
IncludeRef
|
SymbolDisplayLocalOptions
.
IncludeType
,
miscellaneousOptions
:
SymbolDisplayMiscellaneousOptions
.
EscapeKeywordIdentifiers
|
SymbolDisplayMiscellaneousOptions
.
UseSpecialTypes
|
SymbolDisplayMiscellaneousOptions
.
UseErrorTypeSymbolName
|
SymbolDisplayMiscellaneousOptions
.
IncludeNullableReferenceTypeModifier
|
SymbolDisplayMiscellaneousOptions
.
AllowDefaultLiteral
);
[
Fact
]
[
Fact
]
public
void
TestRemoveAttributeSuffix1
()
public
void
TestRemoveAttributeSuffix1
()
{
{
...
...
src/Compilers/Core/Portable/Compilation/Compilation.cs
浏览文件 @
6f87545a
...
@@ -856,6 +856,12 @@ public INamedTypeSymbol GetSpecialType(SpecialType specialType)
...
@@ -856,6 +856,12 @@ public INamedTypeSymbol GetSpecialType(SpecialType specialType)
public
ITypeSymbol
DynamicType
{
get
{
return
CommonDynamicType
;
}
}
public
ITypeSymbol
DynamicType
{
get
{
return
CommonDynamicType
;
}
}
protected
abstract
ITypeSymbol
CommonDynamicType
{
get
;
}
protected
abstract
ITypeSymbol
CommonDynamicType
{
get
;
}
/// <summary>
/// A symbol representing the script globals type.
/// </summary>
internal
ITypeSymbol
?
ScriptGlobalsType
=>
CommonScriptGlobalsType
;
protected
abstract
ITypeSymbol
?
CommonScriptGlobalsType
{
get
;
}
/// <summary>
/// <summary>
/// A symbol representing the implicit Script class. This is null if the class is not
/// A symbol representing the implicit Script class. This is null if the class is not
/// defined in the compilation.
/// defined in the compilation.
...
...
src/Compilers/VisualBasic/Portable/Compilation/VisualBasicCompilation.vb
浏览文件 @
6f87545a
...
@@ -804,6 +804,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
...
@@ -804,6 +804,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Nothing
)
Nothing
)
End
Function
End
Function
Protected
Overrides
ReadOnly
Property
CommonScriptGlobalsType
As
ITypeSymbol
Get
Return
Nothing
End
Get
End
Property
#End Region
#End Region
#Region "Syntax Trees"
#Region "Syntax Trees"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录