【发布时间】:2012-06-26 15:12:29
【问题描述】:
我正在使用 C#,并且我有一个对象,我只能使用 Reflection 访问它(出于某些个人原因)。因此,当我需要为其属性之一设置一些值时,我会执行以下操作:
System.Reflection.PropertyInfo property = this.Parent.GetType().GetProperty("SomeProperty");
object someValue = new object(); // Just for example
property.SetValue(this.Parent, someValue, null);
并且,为了获得它的值,我使用了方法GetValue。
我的问题是:有没有办法在使用反射改变属性时触发事件?
【问题讨论】:
-
这个类是否实现了
INotifyPropertyChanged?调用 SetValue 应该使用属性设置器。 -
@cadrell0,不,恐怕没有
-
@Dante,您找到解决方案了吗?我试图在 Thread.CurrentThread.CurrentCulture 值发生更改时触发通知事件,这与您的问题相似
标签: c# reflection propertychanged