为什么 PropertyInfo.GetValue() 需要实例来检索值?

发布于 2024-12-17 05:39:26 字数 336 浏览 1 评论 0原文

PropertyInfo 类具有 GetValue 方法采用两个参数,第一个是属性的实例。
好吧,这对我来说没有意义,为什么 ProperyInfo 不保存该值? 我从实例获取 PropertyInfo,然后再次需要实例来检索值?!
这很奇怪。

有人可以解释一下为什么 C# 会这样构建吗?

The PropertyInfo class has the GetValue method which takes two parameters, the first one is the instance of the property.
Well it's just doesn't make sense to me, why the ProperyInfo doesn't hold the value?
I get the PropertyInfo from the instance and then I need the Instance again to retrieve the value?!
That's weird.

Can someone please explain me why C# built that way?

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

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

发布评论

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

评论(3

草莓味的萝莉 2024-12-24 05:39:26

PropertyInfo 是“元数据”;它与类型上定义的属性相关联,而不是与实例相关联。

A PropertyInfo is "metadata"; it is associated with a property defined on a type, not an instance.

如梦 2024-12-24 05:39:26

PropertyInfo 类是按类型设计的。 PropertyInfo 类似于类上的属性,而不是实例上的属性。这就是为什么您需要实例来检索值。

The PropertyInfo class is designed on a per-type basis. The PropertyInfo resembles the property on the class, and not on the instance. That's why you need the instance to retrieve the value.

仅一夜美梦 2024-12-24 05:39:26

propertyinfo 仅从实例生成施工计划,而不是值本身

the propertyinfo generates from the instance only the construction plan and not the values itself

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