Is there a way that I can track and intercept calls to values in properties that are auto implemented?
I'd like to have code that looks a bit like this:
[Tracked]
public int SomeProperty { get; set; }
Ideally the attribute would be able to intercept changes to the property values. Is this possible?
What I don't want it to have a second piece of code spin over an object later and request the values, but rather the attribute should tack the value as it is being set.
No. The way you do this is by not using auto properties. The only possible solution there is, is to use something like Castle AOP to create automatic wrappers around your class and have that track the changes, but this is a lot of difficult work to implement.
You should be able to do this with an AOP framework, such as PostSharp (which I note is now commercial). There are a few more linked here, but some of the links are dead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With