views:

50

answers:

2

I am trying to get a MethodInfo object for a method on a type with an out param in its signature. Something to the effect of this:

MethodInfo tryParse = typeof(T).GetMethod(
    "TryParse",
    BindingFlags.Public|BindingFlags.Static,
    null,
    new Type[] { typeof(string), typeof(T) },
    null);

But the problem is, it doesn't find it because the type of the second parameter is not simply T but out T. When I debug through and use typeof(T).GetMethods() I can see the actual MethodInfo that I want and the ParameterInfo object is either of type T& or T ByRef, but I can't see how to create the Type that represents this from typeof(T).

Any ideas?

+1  A: 

I think this article may help you.

Li0liQ
Perfect. Thanks!
McKAMEY
`typeof(T).MakeByRefType()` does the trick beautifully. Thanks.
McKAMEY
A: 

And the very next thing anyone with this question is going to run into is "Okay but how to I invoke it!?!" This article cleared that up for me. Short answer: the arguments array contains the out param, not the variable you used to populate the arguments array.

McKAMEY