I am primarily an Objective-C / Cocoa developer, but I am trying to implement the Observer pattern in C # .NET, in particular, simulate the protocols and methodology of NSKeyValueObserving.
I went so far as to simulate manually supported NSKVOs as described in the Apple KVO Programming Guide (see http://tinyurl.com/nugolr ). Since I am writing the setValue: forKey: methods myself, I can implement automatic KVO notification.
However, I would like to somehow implement automatic KVO for all properties, dynamically redefining them at runtime. For example, replacing Button.Title.set with:
set {
this.willChangeValueForKey("title");
title = value;
this.didChangeValueForKey("title");
}
So this is my question:
How do I dynamically override a method or property at runtime in C #? I got before receiving and calling methods and properties by name using Reflection.MethodInfo. Alternatively, can I watch the runtime and find out when the method will / was called?
source
share