7

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?

johnnyRose
  • 7,310
  • 17
  • 40
  • 61
Dante
  • 3,208
  • 9
  • 38
  • 56
  • Does this class implement `INotifyPropertyChanged`? Calling SetValue should use the properties setter. – cadrell0 Jun 26 '12 at 15:15
  • @cadrell0, No, Im afraid It doesnt – Dante Jun 26 '12 at 15:18
  • @Dante, did you find a solution for this ? I'm trying to trigger a notification event when Thread.CurrentThread.CurrentCulture value is changed which is similar to your question – Kira Aug 24 '15 at 08:59

2 Answers2

8

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.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
0

You can use Inotifychanged in WPF application.. automatically change the property value when some event occured related to property

Vinoth
  • 1