المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : INotifyPropertyChanged, attributes and notification cascade



C# Programming
01-23-2010, 08:40 PM
Hi people,

I have been thinking about a notification system and notification cascade and I came up with the following draft of code (wrote on notepad++, i know i does not compile). I would like to get some more ideas about notification cascading and maybe gather some people to implement something on CodePlex.

Below the snippet there are some resources I found about multiple implementations.

Snippet :


// Avoids having to plumb notifications, is it useful as the class implements the interface?
// INotifyPropertyChanged is useful to know if it is possible to cascade changes
[Notify]
public class MyViewModel :
INotifyPropertyChanged, (INotifier?,) IDisposable,
INotificationConfigurator {
public MyViewModel(AnotherObservableViewModel other){

}

// if property can notify it changed, notify my listeners it changed
// you can filter which properties to cascade
[CascadeNotification(x => x.Pty)]
public AnotherClass MyProperty {
get;set;
}

[DontNotify] // blocks observation
public object YourProperty {
get;set;
}

public void AnActionDelegate(){
// do something
}

public void ConfigureCascades(INotificationEngine notifier){
//Cascade a notification
notifier.CascadeChange(other)
.OnUpdate(other.OtherProperty)
.CascadeOn(this.MyProperty)
.Do(AnActionDelegate)
.OnDispose()
.CascadeDispose();

// or?
notifier.Cascade() // notifier.Cascade(From f, To t) overload ??
.OnUpdate(from => from.OtherProperty)
.CascadeNotificationOn(to => to.MyProperty)
.Do(to => to.AnActionDelegate())
.OnDispose()
.CascadeDispose();
}
}



Resources :

Implementing INotifyPropertyChanged with Unity Interception (http://www.ctrl-shift-b.com/2009/03/implementing-inotifyproperychanged-with.html)[^ (http://www.ctrl-shift-b.com/2009/03/implementing-inotifyproperychanged-with.html)]
Same thing with PostSharp (http://code.google.com/p/propfu/)[^ (http://code.google.com/p/propfu/)]
http://code.google.com/p/postsharp-user-samples/wiki/DataBindingSupport[^ (http://code.google.com/p/postsharp-user-samples/wiki/DataBindingSupport)]
http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/[^ (http://khason.net/dev/inotifypropertychanged-auto-wiring-or-how-to-get-rid-of-redundant-code/)]
http://blogs.msdn.com/knowledgecast/[^ (http://blogs.msdn.com/knowledgecast/)]
http://wpfstarterkit.codeplex.com/Thread/List.aspx[^ (http://wpfstarterkit.codeplex.com/Thread/List.aspx)]
http://jfromaniello.blogspot.com/2009/07/inotifypropertychanged-as-aop.html[^ (http://jfromaniello.blogspot.com/2009/07/inotifypropertychanged-as-aop.html)]
http://shecht.wordpress.com/2009/12/12/inotifypropertychanged-with-unity-interception-aop/[^ (http://shecht.wordpress.com/2009/12/12/inotifypropertychanged-with-unity-interception-aop/)]
http://houseofbilz.com/archive/2009/11/14/adventures-in-mvvm----dependant-properties-with-inotifypropertychanged.aspx[^ (http://houseofbilz.com/archive/2009/11/14/adventures-in-mvvm----dependant-properties-with-inotifypropertychanged.aspx)]