【发布时间】:2010-02-11 13:12:29
【问题描述】:
我正在尝试按如下方式获取 Window 的值
this指主窗口(window1)
Type type = this.GetType();
PropertyInfo pi = type.GetProperty("Left");
object obj = pi.GetValue(type, null);
但我收到“对象与使用的目标类型不匹配”错误。怎么了?
【问题讨论】:
标签: c# .net reflection
我正在尝试按如下方式获取 Window 的值
this指主窗口(window1)
Type type = this.GetType();
PropertyInfo pi = type.GetProperty("Left");
object obj = pi.GetValue(type, null);
但我收到“对象与使用的目标类型不匹配”错误。怎么了?
【问题讨论】:
标签: c# .net reflection
因为您试图获取 Type 的“Left”属性,而不是您的实例。
试试这个
object obj = pi.GetValue(this, null);
【讨论】:
使用此代码
object obj = property.GetValue(currentObject, null);
【讨论】: