Author: miguel
Date: 2007-06-25 18:52:22 -0400 (Mon, 25 Jun 2007)
New Revision: 80737

Modified:
   trunk/olive/class/agclr/ChangeLog
   trunk/olive/class/agclr/Internal.cs
   trunk/olive/class/agclr/Mono/NativeMethods.cs
   trunk/olive/class/agclr/System.Windows/TriggerCollection.cs
Log:
i2007-06-25  Miguel de Icaza  <[EMAIL PROTECTED]>

        * Internal.cs: Make this beast implement ICollection, still a few
        more insterfaces more to go (ICollection<T>, IList, IList<T>)



Modified: trunk/olive/class/agclr/ChangeLog
===================================================================
--- trunk/olive/class/agclr/ChangeLog   2007-06-25 22:46:28 UTC (rev 80736)
+++ trunk/olive/class/agclr/ChangeLog   2007-06-25 22:52:22 UTC (rev 80737)
@@ -1,3 +1,8 @@
+2007-06-25  Miguel de Icaza  <[EMAIL PROTECTED]>
+
+       * Internal.cs: Make this beast implement ICollection, still a few
+       more insterfaces more to go (ICollection<T>, IList, IList<T>)
+
 2007-06-21  Rolf Bjarne Kvinge <[EMAIL PROTECTED]> 
 
        * agclr.dll.sources: Updated.

Modified: trunk/olive/class/agclr/Internal.cs
===================================================================
--- trunk/olive/class/agclr/Internal.cs 2007-06-25 22:46:28 UTC (rev 80736)
+++ trunk/olive/class/agclr/Internal.cs 2007-06-25 22:52:22 UTC (rev 80737)
@@ -33,9 +33,10 @@
 namespace MS.Internal {
        //
        // It seems that this only works for DependencyObjects, but its not in 
-       // the public contract
+       // the public contract, I added the `where' so I can cast 
DependencyObjects
+       // into T's but it might just be that I do not know how to do this.
        //
-       public abstract class Collection<T> : DependencyObject {
+       public abstract class Collection<T> : DependencyObject, ICollection 
where T : DependencyObject {
                public Collection () : base (NativeMethods.collection_new ())
                {
                        NativeMethods.base_ref (native);
@@ -84,7 +85,52 @@
                        else
                                throw new Exception ("The collection only 
supports DependencyObjects");
                }
+
+               //
+               // ICollection members
+               //
+               public int Count {
+                       get {
+                               return NativeMethods.collection_count (native);
+                       }
+               }
+
+               public void CopyTo (Array array, int index)
+               {
+                       if (array == null)
+                               throw new ArgumentNullException ("array");
+
+                       int l = Count;
+                       T [] target = (T []) array;
+                       
+                       for (int i = 0; i < l; i++)
+                               target [index+i] = this [i];
+               }
+
+               public T this [int index] {
+                       get {
+                               IntPtr o = 
NativeMethods.collection_get_value_at (native, index);
+
+                               if (o == IntPtr.Zero)
+                                       throw new ArgumentOutOfRangeException 
("index");
+
+                               Kind k = 
NativeMethods.dependency_object_get_kind (o);
+                               return DependencyObject.Lookup (k, o) as T;
+                       }
+               }
                
+               public object SyncRoot {
+                       get {
+                               return this;
+                       }
+               }
+
+               public bool IsSynchronized {
+                       get {
+                               return false;
+                       }
+               }
+               
                internal override Kind GetKind ()
                {
                        return Kind.COLLECTION;

Modified: trunk/olive/class/agclr/Mono/NativeMethods.cs
===================================================================
--- trunk/olive/class/agclr/Mono/NativeMethods.cs       2007-06-25 22:46:28 UTC 
(rev 80736)
+++ trunk/olive/class/agclr/Mono/NativeMethods.cs       2007-06-25 22:52:22 UTC 
(rev 80737)
@@ -187,6 +187,12 @@
                internal extern static void collection_clear (IntPtr 
collection);
                
                [DllImport("moon")]
+               internal extern static int collection_count (IntPtr collection);
+               
+               [DllImport("moon")]
+               internal extern static IntPtr collection_get_value_at (IntPtr 
collection, int index);
+               
+               [DllImport("moon")]
                internal extern static IntPtr collection_get_iterator (IntPtr 
collection);
 
                [DllImport("moon")]

Modified: trunk/olive/class/agclr/System.Windows/TriggerCollection.cs
===================================================================
--- trunk/olive/class/agclr/System.Windows/TriggerCollection.cs 2007-06-25 
22:46:28 UTC (rev 80736)
+++ trunk/olive/class/agclr/System.Windows/TriggerCollection.cs 2007-06-25 
22:52:22 UTC (rev 80737)
@@ -33,7 +33,7 @@
 
 namespace System.Windows {
 
-       public class TriggerCollection : MS.Internal.Collection<int> {
+       public class TriggerCollection : MS.Internal.Collection<EventTrigger> {
                public TriggerCollection () : base 
(NativeMethods.trigger_collection_new ())
                {
                        NativeMethods.base_ref (native);

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to