Alex Rivera | Logout

Ref parameters and reflection

Asked 2009-10-11T21:01:28.167
39

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?

Edit
Report

1 Answer

7

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.

answered 2009-10-11T21:23:40.463

Your Answer