responding to the model's property changes in asp.net mvc2 -
i having model not in ef, in plain text. have have updated events handled each of model's properties can log changes.
is there way achieved.
implement inotifypropertychanged interface.
a simple example:
using system.componentmodel; public class mymodel : inotifypropertychanged { string _myproperty; public event propertychangedeventhandler propertychanged; public string myproperty { { return _myproperty; } set { _myproperty = value; notifypropertychanged("myproperty"); } } public void notifypropertychanged(string info) { if (propertychanged != null) { propertychanged(this, new propertychangedeventargs(info)); } } }
you can use like...
public class test { public static void main() { var model = new mymodel(); model.propertychanged += new propertychangedeventhandler(logchange); model.myproperty="apples"; model.myproperty="oranges"; model.myproperty="pears"; } public static void logchange(object sender, propertychangedeventargs args) { console.writeline(args.propertyname + " has changed!"); console.writeline("new value: " + sender.gettype().getproperty(args.propertyname) .getvalue(sender, null)); } }
Comments
Post a Comment