开发者

Getting information about a member invoked using Type.InvokeMember()

开发者 https://www.devze.com 2022-12-19 22:31 出处:网络
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 ha

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(...);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号