Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Track calls to auto implemented properties

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.

like image 419
ilivewithian Avatar asked Oct 19 '10 10:10

ilivewithian


2 Answers

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.

like image 200
Pieter van Ginkel Avatar answered Sep 22 '22 07:09

Pieter van Ginkel


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.

like image 43
Noon Silk Avatar answered Sep 23 '22 07:09

Noon Silk