C# CodeDom中的Double类型参考

4

我可以使用CodeMethodInvokeExpressionCodeTypeReferenceExpression来调用某种类型,但我想能够引用以下代码行:

Process p = new Process();
p.StartInfo.FileName = "FilePath";

这是我现在所拥有的——
CodeVariableDeclarationStatement statement = new CodeVariableDeclarationStatement(typeof(System.Diagnostics.Process), "p",
    new CodeObjectCreateExpression("System.Diagnostics.Process",
    new CodeExpression[] { }));

我怎么也想不出如何生成“p.StartInfo.FileName = exFilePath”这行代码。
非常感谢任何关于此事的帮助!
谢谢, Evan

为什么不使用 CodeAssignStatement 来生成 p.StartInfo.FileName = exFilePath - Vlad
@vlad 我考虑过了,但我无法弄清楚如何生成“p.startinfo.filename”这一部分... - user725913
1个回答

1

类似于

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

应该做。


这正是我正在寻找的。CodePropertyReferenceExpression。我会试一下 - 非常感谢。 - user725913
希望这可以帮到你。我对CodeDom并不是很有经验。 - Vlad

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接