Merge pull request #3562 from BrzVlad/fix-reverse-wbarrier
[mono.git] / mcs / class / System.Web / System.Web / HttpCookieCollection.cs
index b668291fc71e24c4ebbee6bc7c1ad199599f7464..e780ff380410b4aa816355d9c2430528f4fe9f02 100644 (file)
@@ -6,7 +6,7 @@
 //
 
 //
-// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
+// Copyright (C) 2005-2009 Novell, Inc (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Collections;
 using System.Collections.Specialized;
-
-namespace System.Web {
-
-       public sealed class HttpCookieCollection : NameObjectCollectionBase {
-
+using System.Security.Permissions;
+
+namespace System.Web
+{
+       // CAS - no InheritanceDemand here as the class is sealed
+       [AspNetHostingPermission (SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)]
+       public sealed class HttpCookieCollection : NameObjectCollectionBase
+       {
                private bool auto_fill = false;
 
                [Obsolete ("Don't use this constructor, use the (bool, bool) one, as it's more clear what it does")]
-               internal HttpCookieCollection (HttpResponse Response, bool ReadOnly)
+               internal HttpCookieCollection (HttpResponse Response, bool ReadOnly) : base (StringComparer.OrdinalIgnoreCase)
                {
                        auto_fill = Response != null;
                        IsReadOnly = ReadOnly;
                }
 
-               internal HttpCookieCollection (bool auto_fill, bool read_only)
+               internal HttpCookieCollection (bool auto_fill, bool read_only) : base (StringComparer.OrdinalIgnoreCase)
                {
                        this.auto_fill = auto_fill;
                        IsReadOnly = read_only;
                }
 
-               internal HttpCookieCollection (string cookies)
+               internal HttpCookieCollection (string cookies) : base (StringComparer.OrdinalIgnoreCase)
                {
-                       if (cookies == null || cookies == "")
+                       if (String.IsNullOrEmpty (cookies))
                                return;
 
                        string[] cookie_components = cookies.Split (';');
@@ -70,15 +74,12 @@ namespace System.Web {
                        }
                }
 
-               public HttpCookieCollection ()
+               public HttpCookieCollection () : base (StringComparer.OrdinalIgnoreCase)
                {
                }
 
                public void Add (HttpCookie cookie)
                {
-                       if (BaseGet (cookie.Name) != null)
-                               return;
-
                        BaseAdd (cookie.Name, cookie);
                }
 
@@ -122,7 +123,7 @@ namespace System.Web {
 
                public HttpCookie Get (string name)
                {
-                       return (HttpCookie)BaseGet (name);
+                       return this [name];
                }
 
                public HttpCookie this [int index]
@@ -146,13 +147,8 @@ namespace System.Web {
 
                public string[] AllKeys {
                        get {
-                               /* XXX another inefficient copy due to
-                                * lack of exposure from the base
-                                * class */
                                string[] keys = new string [Keys.Count];
-                               for (int i = 0; i < Keys.Count; i ++)
-                                       keys[i] = Keys[i];
-                               
+                               ((ICollection)Keys).CopyTo (keys, 0);
                                return keys;
                        }
                }