views:

100

answers:

3

I'm using Type.InvokeMember() to dynamically invoke various members of a Type. Since the members can be generic and also include out parameters etc., I'm happy to have the runtime handle this. However, I also need to have additional information about the actual member that's been invoked -- particularly, the return type. If this type is nullable, I need to do some additional processing.

So, I'd like to know if it's possible to get the MemberInfo object corresponding to the member that was invoked through Type.InvokeMember().

Alternatively, is there a variant of InvokeMember() that simply does the lookup and returns the appropriate MemberInfo object but doesn't actually invoke it? I can then analyze the MemberInfo object, and later invoke it directly.

I haven't been able to find any .NET APIs that do this, so I suspect I'll need to handcode it. Let me know if I'm missing something.

A: 

Alternatively, is there a variant of InvokeMember() that simply does the lookup and returns the appropriate MemberInfo object

You can use the Type.GetMethod method, giving a description of the desired method (name and parameter types). It returns a MethodInfo object which includes the return type.

James Curran
A: 
typeof(yourType).GetMethod(...);
Sky Sanders
A: 

Thanks! I had forgotten that Type.GetMethod() did the same kind of match as InvokeMethod() -- for some reason I had thought it only looked for exact matches!

Wayne Citrin
you should delete this answer and use add comment instead. Since you asked the question you should be able to comment on the answers to it, even at low rep.You should also accept whoever's answer this comment was directed to
ShuggyCoUk