CodeDom Nested Array
As the title suggests, I am trying to "nest" - or create an array within an array in C# using CodeDom.
Here is the line that I am trying to replicate:
T.Invoke(null, new object[] { new string[] {} } );
Where T.Invoke is a method.
I am able to create the above line with almost no flaws. The only issue I have is creating the second set of "{}" 开发者_JAVA技巧brackets. Below is the code I used:
CodeMethodInvokeExpression invoke_expression = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("T"),"Invoke",
new CodePrimitiveExpression(null),
new CodeArrayCreateExpression(typeof(object),
new CodeExpression[] {
new CodeArrayCreateExpression(typeof(string[]),
new CodeExpression[] {})} )));
Perhaps someone could make sense of my code, and maybe even find my error.
Thank you for any help,
Evan
Use an empty CodeSnippetExpression
to coerce it into creating the brackets:
CodeMethodInvokeExpression invoke_expression = new CodeMethodInvokeExpression(
new CodeTypeReferenceExpression("T"),
"Invoke",
new CodePrimitiveExpression(null),
new CodeArrayCreateExpression(
typeof(object),
new CodeExpression[]
{
new CodeArrayCreateExpression(
typeof(string[]),
new CodeExpression[]
{
new CodeSnippetExpression("")
})/*CodeArrayCreateExpression */
})/*CodeArrayCreateExpression */
)/*CodeMethodInvokeExpression*/;
精彩评论