Frage

I am trying to write a CodeAssignStatement which does something equivalent to the following:

this.Foo = row.Field<string>(0);

How to write the RHS expression for the CodeAssignStatement?

So far I only have:

CodeAssignStatement cas = new CodeAssignStatement();
cas.Left = new CodePropertyReferenceExpression(new CodeThisReferenceExpression(), "Foo");
cas.Right = ??!
War es hilfreich?

Lösung

I think you want the CodeTypeReference something like this: (Note that I haven't tested this fully, I've just created the graph - not actually rendered it to code)

cas.Right = new CodeMethodInvokeExpression(
    new CodeMethodReferenceExpression(
        new CodeVariableReferenceExpression("row"),
        "Field",
        new CodeTypeReference("System.String")),
    new CodePrimitiveExpression(0));
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top