Pregunta

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 = ??!
¿Fue útil?

Solución

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));
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top