private int CountDomain(string domain)
        {
            int num = 0;

            foreach (object obj in this.cookies)
            {
                Cookie cookie = (Cookie)obj;
                if (CookieContainer.CheckDomain(domain, cookie.Domain, true))
                {
                    num++;
                }
            }
            return(num);
        }
        /// <summary>Gets a <see cref="T:System.Net.CookieCollection" /> that contains the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</summary>
        /// <returns>A <see cref="T:System.Net.CookieCollection" /> that contains the <see cref="T:System.Net.Cookie" /> instances that are associated with a specific URI.</returns>
        /// <param name="uri">The URI of the <see cref="T:System.Net.Cookie" /> instances desired. </param>
        /// <exception cref="T:System.ArgumentNullException">
        ///   <paramref name="uri" /> is null. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public CookieCollection GetCookies(System.Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            this.CheckExpiration();
            CookieCollection cookieCollection = new CookieCollection();

            if (this.cookies == null)
            {
                return(cookieCollection);
            }
            foreach (object obj in this.cookies)
            {
                Cookie cookie = (Cookie)obj;
                string domain = cookie.Domain;
                if (CookieContainer.CheckDomain(domain, uri.Host, cookie.ExactDomain))
                {
                    if (cookie.Port.Length <= 0 || cookie.Ports == null || uri.Port == -1 || Array.IndexOf <int>(cookie.Ports, uri.Port) != -1)
                    {
                        string path         = cookie.Path;
                        string absolutePath = uri.AbsolutePath;
                        if (path != string.Empty && path != "/" && absolutePath != path)
                        {
                            if (!absolutePath.StartsWith(path))
                            {
                                continue;
                            }
                            if (path[path.Length - 1] != '/' && absolutePath.Length > path.Length && absolutePath[path.Length] != '/')
                            {
                                continue;
                            }
                        }
                        if (!cookie.Secure || !(uri.Scheme != "https"))
                        {
                            cookieCollection.Add(cookie);
                        }
                    }
                }
            }
            cookieCollection.Sort();
            return(cookieCollection);
        }