2008-11-04 Chris Toshok <toshok@ximian.com>
authorChris Toshok <toshok@novell.com>
Tue, 4 Nov 2008 21:07:42 +0000 (21:07 -0000)
committerChris Toshok <toshok@novell.com>
Tue, 4 Nov 2008 21:07:42 +0000 (21:07 -0000)
        * CollectionChangedEventManager.cs: implement this using the msdn
        docs.  Unfortunately we lack the ability to write unit tests at
        the moment, as there's no (that I can find) public use of this
        type in the api.  Certainly not in WindowsBase.

svn path=/trunk/mcs/; revision=117930

mcs/class/WindowsBase/System.Collections.Specialized/ChangeLog [new file with mode: 0644]
mcs/class/WindowsBase/System.Collections.Specialized/CollectionChangedEventManager.cs

diff --git a/mcs/class/WindowsBase/System.Collections.Specialized/ChangeLog b/mcs/class/WindowsBase/System.Collections.Specialized/ChangeLog
new file mode 100644 (file)
index 0000000..5f3dcbd
--- /dev/null
@@ -0,0 +1,7 @@
+2008-11-04  Chris Toshok  <toshok@ximian.com>
+
+       * CollectionChangedEventManager.cs: implement this using the msdn
+       docs.  Unfortunately we lack the ability to write unit tests at
+       the moment, as there's no (that I can find) public use of this
+       type in the api.  Certainly not in WindowsBase.
+
index b4d7e425bde231825e0822e1c24ac72ea737040a..3ee26ef4d5985115b972a614464ac6582c581ea0 100644 (file)
@@ -36,18 +36,44 @@ namespace System.Collections.Specialized {
 
                public static void AddListener (INotifyCollectionChanged source, IWeakEventListener listener)
                {
+                       CurrentManager.ProtectedAddListener (source, listener);
                }
 
                public static void RemoveListener (INotifyCollectionChanged source, IWeakEventListener listener)
                {
+                       CurrentManager.ProtectedAddListener (source, listener);
                }
 
                protected override void StartListening (object source)
                {
+                       INotifyCollectionChanged inotify = (INotifyCollectionChanged) source;
+                       inotify.CollectionChanged += OnCollectionChanged;
                }
 
                protected override void StopListening (object source)
                {
+                       INotifyCollectionChanged inotify = (INotifyCollectionChanged) source;
+                       inotify.CollectionChanged -= OnCollectionChanged;
+               }
+
+               private void OnCollectionChanged (object sender, NotifyCollectionChangedEventArgs e)
+               {
+                       DeliverEvent (sender, e);
+               }
+
+               private static object CurrentManagerLock = new object ();
+
+               private static CollectionChangedEventManager CurrentManager {
+                       get {
+                               lock (CurrentManagerLock) {
+                                       CollectionChangedEventManager manager = GetCurrentManager (typeof (CollectionChangedEventManager));
+                                       if (manager == null) {
+                                               manager = new CollectionChangedEventManager ();
+                                               SetCurrentManager (typeof (CollectionChangedEventManager), manager);
+                                       }
+                                       return manager;
+                               }
+                       }
                }
        }
 }