如何判断 MemberInfo 是否是内部的
确定 MemberInfo
实例是否为内部实例的快速测试是什么?
What is the quick test to determine if an instance of MemberInfo
is internal ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你不能,因为这个问题实际上没有意义。
成员信息可以代表一个属性,而属性不具有可访问性。 (getter 和 setter 具有可访问性,但由于它们可以不同,因此该属性不具有可访问性。)
由于存在不具有可访问性的成员,因此无法仅根据 MemberInfo 确定成员的可访问性。您需要将其转换为 FieldInfo 或 TypeInfo 或任何实际内容,然后询问该对象的可访问性是什么。 (当然,如果它是 PropertyInfo,那么您必须弄清楚您是否对 getter 或 setter 感兴趣,并获取与其关联的方法信息。)
You can't because the question doesn't actually make sense.
A member info could be representing a property, and properties do not have an accessibility. (The getter and setter have an accessibility, but since they can be different, the property does not have an accessibility.)
Since there are members that do not have accessibility, there is no way to determine the accessibility of a member just from a MemberInfo. You'll need to turn it into a FieldInfo or TypeInfo or whatever it actually is and then ask that object what the accessibility is. (And of course if it is a PropertyInfo then you'll have to figure out whether you're interested in the getter or the setter and get the method info associated with it.)