I wrote an interceptor next week for Set, which can be easily expanded for Get, it uses RealProxy, which means that your base class should output MarshalByRefObject.
Another fancy option is to have an abstract class and use Reflection Emit to create a specific class that completes all the properties.
You can also look at code generators to get around this or PostSharp ...
The performance for this solution is not stellar, but for greater UI binding, it should be fast enough. It can be improved by creating LCG methods for calling proxies.
public interface IInterceptorNotifiable { void OnPropertyChanged(string propertyName); }
Using:
class Foo : MarshalByRefObject, IInterceptorNotifiable { public int PublicProp { get; set; } public string lastPropertyChanged; public void OnPropertyChanged(string propertyName) { lastPropertyChanged = propertyName; } } [Test] public void TestPropertyInterception() { var foo = Interceptor<Foo>.Create(); foo.PublicProp = 100; Assert.AreEqual("PublicProp", foo.lastPropertyChanged); } }
Sam saffron
source share