为什么 PropertyInfo.GetValue() 需要实例来检索值?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
PropertyInfo
是“元数据”;它与类型上定义的属性相关联,而不是与实例相关联。A
PropertyInfo
is "metadata"; it is associated with a property defined on a type, not an instance.PropertyInfo
类是按类型设计的。PropertyInfo
类似于类上的属性,而不是实例上的属性。这就是为什么您需要实例来检索值。The
PropertyInfo
class is designed on a per-type basis. ThePropertyInfo
resembles the property on the class, and not on the instance. That's why you need the instance to retrieve the value.propertyinfo 仅从实例生成施工计划,而不是值本身
the propertyinfo generates from the instance only the construction plan and not the values itself