4

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

VMAtm
  • 27,943
  • 17
  • 79
  • 125
  • why not produce `p.StartInfo.FileName = exFilePath` with [`CodeAssignStatement`](http://msdn.microsoft.com/en-us/library/system.codedom.codeassignstatement.aspx)? – Vlad Jul 17 '11 at 17:20
  • @vlad I have considered that but I can't figure out how to generate the "p.startinfo.filename" part of that ... –  Jul 17 '11 at 17:23

1 Answers1

1

Something like

new CodeAssignStatement(
    new CodePropertyReferenceExpression(
        new CodePropertyReferenceExpression(
              new CodeVariableReferenceExpression("p"),
              "StartInfo"),
        "FileName"),
    new CodePrimitiveExpression("FilePath"))

should do.

Vlad
  • 35,022
  • 6
  • 77
  • 199
  • This is exactly what I was looking for . CodePropertyReferenceExpression. I will give this a go - thank you very much –  Jul 17 '11 at 17:26
  • Hope this helps. I'm not very experienced with CodeDom. – Vlad Jul 17 '11 at 17:28