简体   繁体   中英

Raise an event when Property Changed using Reflection

I am working in C# and I have an object which I can only access using Reflection (for some personal reasons). So, when I need to set some value to one of its properties I do as below:

System.Reflection.PropertyInfo property = this.Parent.GetType().GetProperty("SomeProperty");
object someValue = new object(); // Just for example
property.SetValue(this.Parent, someValue, null);

And, to get its value I use the method GetValue .

My question is: Is there a way to fire an event when the property changes using Reflection?

Is there a way to fire an event when the property changes using Reflection?

Not unless the property setter itself raises it, no. There's nothing "watching" for all properties changing, and raising events when they do.

您可以在WPF应用程序中使用Inotifychanged ..在与属性相关的某个事件发生时自动更改属性值

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM