GetMethod

  • Thread starter Thread starter Picho
  • Start date Start date
P

Picho

Hi all,

when using the GetMethod method to discover object methods at runtime, we
are suposed to pass an array of types as parameters.

My simple question is this:

how do you state that one of the parameters is by reference (i.e. void
myMethod(ref object) )?
in other words, if I have the following types array:

Type[] parmTypes = new Type[3];

parmTypes[0] = Type.GetType("System.String");

parmTypes[1] = Type.GetType("System.String");

parmTypes[2] = Type.GetType("System.String");



I wish to state that one or all of them is a 'ref' argument.



Thanx,

Picho
 
Picho said:
when using the GetMethod method to discover object methods at runtime, we
are suposed to pass an array of types as parameters.

My simple question is this:

how do you state that one of the parameters is by reference (i.e. void
myMethod(ref object) )?
in other words, if I have the following types array:

Type[] parmTypes = new Type[3];
parmTypes[0] = Type.GetType("System.String");
parmTypes[1] = Type.GetType("System.String");
parmTypes[2] = Type.GetType("System.String");

I wish to state that one or all of them is a 'ref' argument.

I believe you just append an "&" at the end:

parmTypes[2] = Type.GetType("System.String&");

Note that for "normal" parameters, a simpler way of specifying the type
is using the typeof operator:

parmTypes[0] = typeof(string);

I believe that in the next version of .NET there'll be a way of getting
a "by reference" version of a "normal" type, which will make all this
significantly easier.
 
Thanx Jon,

I realized tht after invoking a GetParameters after GetMethod(string name)
on a test method that had a ref argument...

Picho


Jon Skeet said:
Picho said:
when using the GetMethod method to discover object methods at runtime, we
are suposed to pass an array of types as parameters.

My simple question is this:

how do you state that one of the parameters is by reference (i.e. void
myMethod(ref object) )?
in other words, if I have the following types array:

Type[] parmTypes = new Type[3];
parmTypes[0] = Type.GetType("System.String");
parmTypes[1] = Type.GetType("System.String");
parmTypes[2] = Type.GetType("System.String");

I wish to state that one or all of them is a 'ref' argument.

I believe you just append an "&" at the end:

parmTypes[2] = Type.GetType("System.String&");

Note that for "normal" parameters, a simpler way of specifying the type
is using the typeof operator:

parmTypes[0] = typeof(string);

I believe that in the next version of .NET there'll be a way of getting
a "by reference" version of a "normal" type, which will make all this
significantly easier.
 
Back
Top