Reflection and PropertyInfo

  • Thread starter Thread starter Picho
  • Start date Start date
P

Picho

Hi guys

is it possible, once getting hold of a propertyInfo instance to know when
the value of the property changed?

that is without requiring the property to raise an event on change
obviously...

maybe something with the PropertyInfo.GetSetMethod()? monitoring when that
method is called somehow?

how does the dataBinding mechanism work? seems to do the job, but how?

thanx,

Picho
 
No, there's no way to do it using PropertyInfo, for two reasons.

First (and most obvious) because there's no such mechanism in .NET.

Second (even if there were such a mechanism), a PropertyInfo instance
_doesn't remember_ which object instance it came from (if any). Here
proof: you can get a PropertyInfo without having an instance of the
object at all:

PropertyInfo pi = typeof(MyClass).GetProperty("PropertyName");

PropertyInfo is pure metadata: it contains no information about any
object instance, so it can't help you if something about the instance
changes.

As to your second question, bindings do their job by requiring that
every property they're monitoring have a "...Changed" event. So, if you
have a class with a "BalanceDue" property, if you define an event
called "BalanceDueChanged" then you can bind that property to some
screen control using a binding. No event, no successful binding. No
magic involved at all. :)
 
Well, Figures.

thanx, I guess I have to stick to the OnChange thing.

b.t.w: is there a naming convention to link the property name to the event
name for the DataBinding to work?

thanx

Picho
 
Back
Top