tags:

views:

300

answers:

2

I'm not sure if I'm totally missing something here but I can't find any way to determine if a parameter is passed by reference or not by using reflection.

ArgumentInfo has a property "IsOut", but no "IsRef". How would I go about to get all reference parameters in a given MethodInfo?

+8  A: 
ParameterInfo[] parameters = myMethodInfo.GetParameters();
foreach(ParameterInfo parameter in parameters)
{
    bool isRef = parameterInfo.ParameterType.IsByRef;
}
Rex M
IsByRef does only determine if the Type is a reference Type or a value Type as far as I can tell, it does not tell you if the Type if being pass by reference
Jorge Córdoba
Patrik Hägne
Jorge: What you are talking about is `IsValueType`, not `IsByRef`.
Mehrdad Afshari
+3  A: 

You need to examine the type of your parameter further. For example if you have

void Foo(ref int bar)

then the name of the parameter wouldn't be int or Int32 (as you might have expected) but instead Int32&. For every type there is a correspondent by-ref-type where the original type is suffixed by a '&'. You can check this via the IsByRef property of the Type class.

Christian Rodemeyer