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.
I figured out the solution for this. I should be using
CodeDirectionExpression. Here's how it is done.
[Code]
// 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:
JustAnotherP...
Member
35 Points
7 Posts
Passing arguments to a method using CodeDOM
Oct 05, 2005 01:01 PM|LINK
Any help to solve this is appreciated.
JustAnotherP...
Member
35 Points
7 Posts
Re: Passing arguments to a method using CodeDOM
Oct 06, 2005 08:04 PM|LINK
I figured out the solution for this. I should be using CodeDirectionExpression. Here's how it is done.
[Code]
// 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);
[Code]