Passing arguments to a method using CodeDOM RRS feed

  • Question

  • User-135741485 posted
    I'm trying to pass arguments by ref to a method using codedom and I could not find how to do this. If I use: CodeParameterDeclarationExpression, it shows ref void next to the argument and I could not find Direction property in CodeArgumentReferenceExpression.

    Any help to solve this is appreciated.
    Wednesday, October 5, 2005 9:01 AM

All replies

  • User-135741485 posted

    I figured out the solution for this. I should be using CodeDirectionExpression. Here's how it is done.

    // Declares a parameter passed by reference using a CodeDirectionExpression.
    CodeDirectionExpression param1 = new CodeDirectionExpression(FieldDirection.Ref, new CodeFieldReferenceExpression( new CodeThisReferenceExpression(), "TestParameter" ));
    // Invokes a method on this named TestMethod using the direction expression as a parameter.
    CodeMethodInvokeExpression methodInvoke1 = new CodeMethodInvokeExpression(new CodeThisReferenceExpression(), "TestMethod", param1 );

    // A C# code generator produces the following source code for the preceeding example code:   

    //        this.TestMethod(ref TestParameter);

    Thursday, October 6, 2005 4:04 PM