我正在使用C#进行工作,我有一个对象,基于一些个人原因,只能使用反射
来访问该对象。因此,当我需要设置其中一个属性的值时,我会按照以下方式操作:
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 应该使用属性的 setter。 - cadrell0