Reputation:
I am able to make a call to some type by using CodeMethodInvokeExpression
along with CodeTypeReferenceExpression
, but I would like to be able to make a reference to the following line of code:
Process p = new Process();
p.StartInfo.FileName = "FilePath";
Here is what I've got so far -
CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(System.Diagnostics.Process), "p",
new CodeObjectCreateExpression("System.Diagnostics.Process",
new CodeExpression[] { }));
I cannot figure out how to produce the line "p.StartInfo.FileName = exFilePath" for the life of me.
Any help on the matter would be greatly appreciated!
Thank you, Evan
Upvotes: 4
Views: 122
Reputation: 35594
Something like
new CodeAssignStatement(
new CodePropertyReferenceExpression(
new CodePropertyReferenceExpression(
new CodeVariableReferenceExpression("p"),
"StartInfo"),
"FileName"),
new CodePrimitiveExpression("FilePath"))
should do.
Upvotes: 1