Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
a5fc939b
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,发现更多精彩内容 >>
提交
a5fc939b
编写于
7月 29, 2015
作者:
C
Charles Stoner
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4188 from cston/Ext
Allow top-level extension methods in VB script code
上级
a637d95d
5f7a42bc
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
4 deletion
+62
-4
src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbolExtensions.vb
...VisualBasic/Portable/Symbols/NamedTypeSymbolExtensions.vb
+5
-0
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb
...ortable/Symbols/Source/SourceMemberContainerTypeSymbol.vb
+1
-1
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberMethodSymbol.vb
...Basic/Portable/Symbols/Source/SourceMemberMethodSymbol.vb
+1
-1
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb
...VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb
+2
-2
src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/ExtensionMethods/ExtensionMethodTests.vb
...bol/SymbolsTests/ExtensionMethods/ExtensionMethodTests.vb
+53
-0
未找到文件。
src/Compilers/VisualBasic/Portable/Symbols/NamedTypeSymbolExtensions.vb
浏览文件 @
a5fc939b
...
...
@@ -113,5 +113,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return
False
End
Function
<
Extension
()
>
Friend
Function
AllowsExtensionMethods
(
container
As
NamedTypeSymbol
)
As
Boolean
Return
container
.
TypeKind
=
TypeKind
.
Module
OrElse
container
.
IsScriptClass
End
Function
End
Module
End
Namespace
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberContainerTypeSymbol.vb
浏览文件 @
a5fc939b
...
...
@@ -3333,7 +3333,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' Only Modules can declare extension methods.
If
_lazyContainsExtensionMethods
=
ThreeState
.
Unknown
Then
If
Not
(
_containingSymbol
.
Kind
=
SymbolKind
.
Namespace
AndAlso
Me
.
TypeKind
=
TypeKind
.
Module
AndAlso
Me
.
AnyMemberHasAttributes
)
Then
If
Not
(
_containingSymbol
.
Kind
=
SymbolKind
.
Namespace
AndAlso
Me
.
AllowsExtensionMethods
()
AndAlso
Me
.
AnyMemberHasAttributes
)
Then
_lazyContainsExtensionMethods
=
ThreeState
.
False
End
If
End
If
...
...
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMemberMethodSymbol.vb
浏览文件 @
a5fc939b
...
...
@@ -85,7 +85,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' Check attributes quickly.
_quickAttributes
=
binder
.
QuickAttributeChecker
.
CheckAttributes
(
syntax
.
AttributeLists
)
If
containingType
.
TypeKind
<>
TypeKind
.
Module
Then
If
Not
containingType
.
AllowsExtensionMethods
()
Then
' Extension methods in source can only be inside modules.
_quickAttributes
=
_quickAttributes
And
Not
QuickAttributes
.
Extension
End
If
...
...
src/Compilers/VisualBasic/Portable/Symbols/Source/SourceMethodSymbol.vb
浏览文件 @
a5fc939b
...
...
@@ -1471,7 +1471,7 @@ lReportErrorOnTwoTokens:
Dim
isExtensionMethod
As
Boolean
=
False
If
Not
(
Me
.
MethodKind
<>
MethodKind
.
Ordinary
AndAlso
Me
.
MethodKind
<>
MethodKind
.
DeclareMethod
)
AndAlso
m_containingType
.
TypeKind
=
TYPEKIND
.
Module
AndAlso
m_containingType
.
AllowsExtensionMethods
()
AndAlso
Me
.
ParameterCount
<>
0
Then
Debug
.
Assert
(
Me
.
IsShared
)
...
...
@@ -1569,7 +1569,7 @@ lReportErrorOnTwoTokens:
If
Me
.
MethodKind
<>
MethodKind
.
Ordinary
AndAlso
Me
.
MethodKind
<>
MethodKind
.
DeclareMethod
Then
arguments
.
Diagnostics
.
Add
(
ERRID
.
ERR_ExtensionOnlyAllowedOnModuleSubOrFunction
,
arguments
.
AttributeSyntaxOpt
.
GetLocation
())
ElseIf
m_containingType
.
TypeKind
<>
TYPEKIND
.
Module
Then
ElseIf
Not
m_containingType
.
AllowsExtensionMethods
()
Then
arguments
.
Diagnostics
.
Add
(
ERRID
.
ERR_ExtensionMethodNotInModule
,
arguments
.
AttributeSyntaxOpt
.
GetLocation
())
ElseIf
Me
.
ParameterCount
=
0
Then
...
...
src/Compilers/VisualBasic/Test/Symbol/SymbolsTests/ExtensionMethods/ExtensionMethodTests.vb
浏览文件 @
a5fc939b
...
...
@@ -2431,6 +2431,59 @@ End Module
End
Sub
<
Fact
>
Public
Sub
ScriptExtensionMethods
()
Dim
comp
=
CreateCompilationWithMscorlib
(
<
compilation
>
<
file
name
=
"a.vbx"
><
!
[
CDATA
[
Imports
System.Runtime.CompilerServices
<
Extension
>
Shared
Function
F
(
o
As
Object
)
As
Object
Return
Nothing
End
Function
Dim
o
As
New
Object
()
o
.
F
()
]]
></
file
>
</
compilation
>
,
parseOptions
:
=
TestOptions
.
Script
,
references
:
=
{
MscorlibRef
,
SystemCoreRef
})
comp
.
VerifyDiagnostics
()
Assert
.
True
(
comp
.
SourceAssembly
.
MightContainExtensionMethods
)
End
Sub
<
Fact
>
Public
Sub
InteractiveExtensionMethods
()
Dim
parseOptions
=
TestOptions
.
Interactive
Dim
references
=
{
MscorlibRef
,
SystemCoreRef
}
Dim
source0
=
<
!
[
CDATA
[
Imports
System.Runtime.CompilerServices
<
Extension
>
Shared
Function
F
(
o
As
Object
)
As
Object
Return
0
End
Function
Dim
o
As
New
Object
()
?
o
.
F
()
]]
>
Dim
source1
=
<
!
[
CDATA
[
<
Extension
>
Shared
Function
G
(
o
As
Object
)
As
Object
Return
1
End
Function
Dim
o
As
New
Object
()
?
o
.
G
().
F
()
]]
>
Dim
s0
=
VisualBasicCompilation
.
CreateSubmission
(
"s0.dll"
,
syntaxTree
:
=
Parse
(
source0
.
Value
,
parseOptions
),
references
:
=
references
)
s0
.
VerifyDiagnostics
()
Assert
.
True
(
s0
.
SourceAssembly
.
MightContainExtensionMethods
)
Dim
s1
=
VisualBasicCompilation
.
CreateSubmission
(
"s1.dll"
,
syntaxTree
:
=
Parse
(
source0
.
Value
,
parseOptions
),
previousSubmission
:
=
s0
,
references
:
=
references
)
s1
.
VerifyDiagnostics
()
Assert
.
True
(
s1
.
SourceAssembly
.
MightContainExtensionMethods
)
End
Sub
End
Class
End
Namespace
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录