Getting information about a member invoked using Type.InvokeMember()
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.
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.
typeof(yourType).GetMethod(...);
精彩评论