c# 如何从PropertyInfo获取base.Name

发布于 2024-07-16 14:56:47 字数 285 浏览 5 评论 0原文

我正在逐步执行一些代码并查看 PropertyInfo 对象,并想知道如何获取其 base.Name

alt text http://www.yart.com.au/stackoverflow/propertyinfo.png

我可以在调试器中看到这一点,但我不知道如何执行此操作,因为没有“基本”属性在 PropertyInfo 上

I am stepping though some code and looking at a PropertyInfo object and want to know how to get its base.Name

alt text http://www.yart.com.au/stackoverflow/propertyinfo.png

I can see this in the debugger but I am not sure how to do this as there is no "base" property on a PropertyInfo

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

青春如此纠结 2024-07-23 14:56:47

您可以通过 property.Name 访问此属性。

调试器显示 base.Name 的事实有点用词不当。 实际上,C# EE 正在幕后评估 property.Name。 它实际上并不评估“base.Name”。

无论属性/方法是否是虚拟的,都是如此。 原因是 CLR 调试器没有提供 EE 在非虚拟方法中调用虚拟方法的方法。 有多种方法可以通过反射调用方法来实现此效果,但 C# 或 VB.Net 在各自的 EE 中都没有走这条路。

You can access this property via property.Name.

The fact that the debugger shows base.Name is a bit of a misnomer. In reality the C# EE is evaluating property.Name under the hood. It does not actually evaluate "base.Name".

This is true regardless of whether or not the property / method is virtual. The reason being that the CLR deubgger provides no means by which the EE can invoke a virtual method in a non-virtual method. There are ways to call a method via relfection to achieve this effect but neither C# or VB.Net go this route in their respective EE's.

挽清梦 2024-07-23 14:56:47

只需使用.NamePropertyInfo 没有定义它 - 它从 MemberInfo 继承它

Just use .Name; PropertyInfo doesn't define this - it inherits it from MemberInfo

木格 2024-07-23 14:56:47

只是:

property.Name

Just:

property.Name
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文