2008-11-04 Gonzalo Paniagua Javier <gonzalo@novell.com>
[mono.git] / mcs / class / System / System.Net / CookieCollection.cs
index 2303ac7891fd241baf5c2038a3e3a86adc909cfe..a7528bdf8df03facdcc4f908a0b07782ecea5f3b 100644 (file)
@@ -39,6 +39,20 @@ namespace System.Net
        [Serializable]
        public class CookieCollection : ICollection, IEnumerable
        {
+               class CookieCollectionPathComparer : IComparer
+               {
+                       int IComparer.Compare (object p1, object p2)
+                       {
+                               Cookie c1 = p1 as Cookie;
+                               Cookie c2 = p2 as Cookie;
+
+                               if (c1 == null || c2 == null)
+                                       return 0;
+                               
+                               return (c2.Path.Length - c1.Path.Length);
+                       }
+               }
+               
                ArrayList list = new ArrayList (4);
 
                internal ArrayList List {
@@ -62,6 +76,13 @@ namespace System.Net
                        list.CopyTo (array, arrayIndex);
                }
 
+#if NET_2_0
+               public void CopyTo (Cookie [] array, int index)
+               {
+                       list.CopyTo (array, index);
+               }
+#endif
+
                // IEnumerable
                public IEnumerator GetEnumerator ()
                {
@@ -89,6 +110,14 @@ namespace System.Net
                                list [pos] = cookie;
                }
 
+               internal void SortByPath ()
+               {
+                       if (list == null || list.Count == 0)
+                               return;
+
+                       list.Sort (new CookieCollectionPathComparer ());
+               }
+               
                int SearchCookie (Cookie cookie)
                {
                        string name = cookie.Name;