简体   繁体   English

C# CodeDom Double Type 参考

[英]C# CodeDom Double Type Reference

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:我可以通过使用CodeMethodInvokeExpressionCodeTypeReferenceExpression来调用某种类型,但我希望能够引用以下代码行:

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.我无法弄清楚如何为我的一生生成“p.StartInfo.FileName = exFilePath”行。

Any help on the matter would be greatly appreciated!任何有关此事的帮助将不胜感激!

Thank you, Evan谢谢你,埃文

Something like就像是

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

should do.应该做。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM