MethodInfo可以用作Dictionary键吗? [英] Can MethodInfo be used as Dictionary key?

查看:64
本文介绍了MethodInfo可以用作Dictionary键吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道MethodInfo是否适合用作字典键.从我非常有限的测试来看,一切似乎都很好,但是这里有陷阱吗?

I'm wondering whether MethodInfo is suitable for use as dictionary key. From my very limited test, everything seems fine, but is there any gotcha here?

有人做过吗?

推荐答案

MethodInfo是一个抽象类,因此您的问题不能直接回答.最常见的情况是,您获得了带有反射的引用,并获得了RuntimeMethodInfo实例.是的,它具有对Equals()方法以及GetHashCode()的精心重写.它处理了通用方法的特殊情况.链接的博客文章仅与GetCurrentMethod()有关.使用调试器查找具体的类类型.

MethodInfo is an abstract class so your question is not directly answerable. The most common case is where you obtained a reference with Reflection, you get a RuntimeMethodInfo instance. And yes, it has an elaborate override for the Equals() method, as well as GetHashCode(). It deals with the special case of the method being generic. The linked blog post is only relevant for GetCurrentMethod(). Use the debugger to find the concrete class type.

这篇关于MethodInfo可以用作Dictionary键吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆