Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
7928f74c
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,发现更多精彩内容 >>
提交
7928f74c
编写于
10月 07, 2015
作者:
M
Matt Warren
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4925 from mattwar/Issue3829
Add ArrayCreationExpression to SyntaxGenerator
上级
4ab34d56
70fa355d
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
69 addition
and
0 deletion
+69
-0
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
...s/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
+18
-0
src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs
...kspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs
+12
-0
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
+10
-0
src/Workspaces/Core/Portable/PublicAPI.Unshipped.txt
src/Workspaces/Core/Portable/PublicAPI.Unshipped.txt
+2
-0
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
...sic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
+16
-0
src/Workspaces/VisualBasicTest/CodeGeneration/SyntaxGeneratorTests.vb
...es/VisualBasicTest/CodeGeneration/SyntaxGeneratorTests.vb
+11
-0
未找到文件。
src/Workspaces/CSharp/Portable/CodeGeneration/CSharpSyntaxGenerator.cs
浏览文件 @
7928f74c
...
...
@@ -3421,6 +3421,24 @@ private ExpressionSyntax ParenthesizeLeft(ExpressionSyntax expression)
}
}
private
SeparatedSyntaxList
<
ExpressionSyntax
>
AsExpressionList
(
IEnumerable
<
SyntaxNode
>
expressions
)
{
return
SyntaxFactory
.
SeparatedList
(
expressions
.
OfType
<
ExpressionSyntax
>());
}
public
override
SyntaxNode
ArrayCreationExpression
(
SyntaxNode
elementType
,
SyntaxNode
size
)
{
var
arrayType
=
SyntaxFactory
.
ArrayType
((
TypeSyntax
)
elementType
,
SyntaxFactory
.
SingletonList
(
SyntaxFactory
.
ArrayRankSpecifier
(
SyntaxFactory
.
SingletonSeparatedList
((
ExpressionSyntax
)
size
))));
return
SyntaxFactory
.
ArrayCreationExpression
(
arrayType
);
}
public
override
SyntaxNode
ArrayCreationExpression
(
SyntaxNode
elementType
,
IEnumerable
<
SyntaxNode
>
elements
)
{
var
arrayType
=
SyntaxFactory
.
ArrayType
((
TypeSyntax
)
elementType
,
SyntaxFactory
.
SingletonList
(
SyntaxFactory
.
ArrayRankSpecifier
()));
var
initializer
=
SyntaxFactory
.
InitializerExpression
(
SyntaxKind
.
ArrayInitializerExpression
,
AsExpressionList
(
elements
));
return
SyntaxFactory
.
ArrayCreationExpression
(
arrayType
,
initializer
);
}
public
override
SyntaxNode
ObjectCreationExpression
(
SyntaxNode
type
,
IEnumerable
<
SyntaxNode
>
arguments
)
{
return
SyntaxFactory
.
ObjectCreationExpression
((
TypeSyntax
)
type
,
CreateArgumentList
(
arguments
),
null
);
...
...
src/Workspaces/CSharpTest/CodeGeneration/SyntaxGeneratorTests.cs
浏览文件 @
7928f74c
...
...
@@ -313,6 +313,18 @@ public void TestMemberAccessExpressions()
VerifySyntax
<
MemberAccessExpressionSyntax
>(
_g
.
MemberAccessExpression
(
_g
.
NegateExpression
(
_g
.
IdentifierName
(
"x"
)),
_g
.
IdentifierName
(
"y"
)),
"(-(x)).y"
);
}
[
Fact
]
public
void
TestArrayCreationExpressions
()
{
VerifySyntax
<
ArrayCreationExpressionSyntax
>(
_g
.
ArrayCreationExpression
(
_g
.
IdentifierName
(
"x"
),
_g
.
LiteralExpression
(
10
)),
"new x[10]"
);
VerifySyntax
<
ArrayCreationExpressionSyntax
>(
_g
.
ArrayCreationExpression
(
_g
.
IdentifierName
(
"x"
),
new
SyntaxNode
[]
{
_g
.
IdentifierName
(
"y"
),
_g
.
IdentifierName
(
"z"
)
}),
"new x[]{y, z}"
);
}
[
Fact
]
public
void
TestObjectCreationExpressions
()
{
...
...
src/Workspaces/Core/Portable/Editing/SyntaxGenerator.cs
浏览文件 @
7928f74c
...
...
@@ -1625,6 +1625,16 @@ public SyntaxNode MemberAccessExpression(SyntaxNode expression, string memberNam
return
MemberAccessExpression
(
expression
,
IdentifierName
(
memberName
));
}
/// <summary>
/// Creates an array creation expression for a single dimensional array of specified size.
/// </summary>
public
abstract
SyntaxNode
ArrayCreationExpression
(
SyntaxNode
elementType
,
SyntaxNode
size
);
/// <summary>
/// Creates an array creation expression for a single dimensional array with specified initial element values.
/// </summary>
public
abstract
SyntaxNode
ArrayCreationExpression
(
SyntaxNode
elementType
,
IEnumerable
<
SyntaxNode
>
elements
);
/// <summary>
/// Creates an object creation expression.
/// </summary>
...
...
src/Workspaces/Core/Portable/PublicAPI.Unshipped.txt
浏览文件 @
7928f74c
Microsoft.CodeAnalysis.Editing.SyntaxEditor.RemoveNode(Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) -> void
Microsoft.CodeAnalysis.Project.IsSubmission.get -> bool
Microsoft.CodeAnalysis.Workspace.UpdateReferencesAfterAdd() -> void
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.ArrayCreationExpression(Microsoft.CodeAnalysis.SyntaxNode elementType, Microsoft.CodeAnalysis.SyntaxNode size) -> Microsoft.CodeAnalysis.SyntaxNode
abstract Microsoft.CodeAnalysis.Editing.SyntaxGenerator.ArrayCreationExpression(Microsoft.CodeAnalysis.SyntaxNode elementType, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.SyntaxNode> elements) -> Microsoft.CodeAnalysis.SyntaxNode
static Microsoft.CodeAnalysis.CodeActions.CodeAction.Create(string title, System.Collections.Generic.IEnumerable<Microsoft.CodeAnalysis.CodeActions.CodeAction> nestedActions, string equivalenceKey = null) -> Microsoft.CodeAnalysis.CodeActions.CodeAction
static Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetGenerator(Microsoft.CodeAnalysis.Project project) -> Microsoft.CodeAnalysis.Editing.SyntaxGenerator
virtual Microsoft.CodeAnalysis.Editing.SyntaxGenerator.RemoveNode(Microsoft.CodeAnalysis.SyntaxNode root, Microsoft.CodeAnalysis.SyntaxNode node, Microsoft.CodeAnalysis.SyntaxRemoveOptions options) -> Microsoft.CodeAnalysis.SyntaxNode
\ No newline at end of file
src/Workspaces/VisualBasic/Portable/CodeGeneration/VisualBasicSyntaxGenerator.vb
浏览文件 @
7928f74c
...
...
@@ -224,6 +224,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.CodeGeneration
Return
SyntaxFactory
.
UnaryMinusExpression
(
Parenthesize
(
expression
))
End
Function
Private
Function
AsExpressionList
(
expressions
As
IEnumerable
(
Of
SyntaxNode
))
As
SeparatedSyntaxList
(
Of
ExpressionSyntax
)
Return
SyntaxFactory
.
SeparatedList
(
Of
ExpressionSyntax
)(
expressions
.
OfType
(
Of
ExpressionSyntax
)())
End
Function
Public
Overrides
Function
ArrayCreationExpression
(
elementType
As
SyntaxNode
,
size
As
SyntaxNode
)
As
SyntaxNode
Dim
sizes
=
SyntaxFactory
.
ArgumentList
(
SyntaxFactory
.
SingletonSeparatedList
(
AsArgument
(
size
)))
Dim
initializer
=
SyntaxFactory
.
CollectionInitializer
()
Return
SyntaxFactory
.
ArrayCreationExpression
(
Nothing
,
DirectCast
(
elementType
,
TypeSyntax
),
sizes
,
initializer
)
End
Function
Public
Overrides
Function
ArrayCreationExpression
(
elementType
As
SyntaxNode
,
elements
As
IEnumerable
(
Of
SyntaxNode
))
As
SyntaxNode
Dim
sizes
=
SyntaxFactory
.
ArgumentList
()
Dim
initializer
=
SyntaxFactory
.
CollectionInitializer
(
AsExpressionList
(
elements
))
Return
SyntaxFactory
.
ArrayCreationExpression
(
Nothing
,
DirectCast
(
elementType
,
TypeSyntax
),
sizes
,
initializer
)
End
Function
Public
Overloads
Overrides
Function
ObjectCreationExpression
(
typeName
As
SyntaxNode
,
arguments
As
IEnumerable
(
Of
SyntaxNode
))
As
SyntaxNode
Return
SyntaxFactory
.
ObjectCreationExpression
(
Nothing
,
...
...
src/Workspaces/VisualBasicTest/CodeGeneration/SyntaxGeneratorTests.vb
浏览文件 @
7928f74c
...
...
@@ -327,6 +327,17 @@ End Class
VerifySyntax
(
Of
MemberAccessExpressionSyntax
)(
_g
.
MemberAccessExpression
(
_g
.
NegateExpression
(
_g
.
IdentifierName
(
"x"
)),
_g
.
IdentifierName
(
"y"
)),
"(-(x)).y"
)
End
Sub
<
Fact
>
Public
Sub
TestArrayCreationExpressions
()
VerifySyntax
(
Of
ArrayCreationExpressionSyntax
)(
_g
.
ArrayCreationExpression
(
_g
.
IdentifierName
(
"x"
),
_g
.
LiteralExpression
(
10
)),
"New x(10) {}"
)
VerifySyntax
(
Of
ArrayCreationExpressionSyntax
)(
_g
.
ArrayCreationExpression
(
_g
.
IdentifierName
(
"x"
),
{
_g
.
IdentifierName
(
"y"
),
_g
.
IdentifierName
(
"z"
)}),
"New x() {y, z}"
)
End
Sub
<
Fact
>
Public
Sub
TestObjectCreationExpressions
()
VerifySyntax
(
Of
ObjectCreationExpressionSyntax
)(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录