System.Net.Cookie.Clone C# (CSharp) Method

Clone() private method

private Clone ( ) : Cookie
return Cookie
        internal Cookie Clone()
        {
            Cookie clonedCookie = new Cookie(_name, _value);

            // Copy over all the properties from the original cookie
            if (!_portImplicit)
            {
                clonedCookie.Port = _port;
            }
            if (!_pathImplicit)
            {
                clonedCookie.Path = _path;
            }
            clonedCookie.Domain = _domain;

            // If the domain in the original cookie was implicit, we should preserve that property
            clonedCookie.DomainImplicit = _domainImplicit;
            clonedCookie._timeStamp = _timeStamp;
            clonedCookie.Comment = _comment;
            clonedCookie.CommentUri = _commentUri;
            clonedCookie.HttpOnly = _httpOnly;
            clonedCookie.Discard = _discard;
            clonedCookie.Expires = _expires;
            clonedCookie.Version = _version;
            clonedCookie.Secure = _secure;

            // The variant is set when we set properties like port/version. So, 
            // we should copy over the variant from the original cookie after 
            // we set all other properties
            clonedCookie._cookieVariant = _cookieVariant;

            return clonedCookie;
        }

Usage Example

        public void Add(Cookie cookie)
        {
            Uri uri;

            if (cookie == null)
            {
                throw new ArgumentNullException("cookie");
            }
            if (cookie.Domain.Length == 0)
            {
                throw new ArgumentException(SR.GetString("net_emptystringcall"), "cookie.Domain");
            }
            StringBuilder builder = new StringBuilder();

            builder.Append(cookie.Secure ? Uri.UriSchemeHttps : Uri.UriSchemeHttp).Append(Uri.SchemeDelimiter);
            if (!cookie.DomainImplicit && (cookie.Domain[0] == '.'))
            {
                builder.Append("0");
            }
            builder.Append(cookie.Domain);
            if (cookie.PortList != null)
            {
                builder.Append(":").Append(cookie.PortList[0]);
            }
            builder.Append(cookie.Path);
            if (!Uri.TryCreate(builder.ToString(), UriKind.Absolute, out uri))
            {
                throw new CookieException(SR.GetString("net_cookie_attribute", new object[] { "Domain", cookie.Domain }));
            }
            Cookie cookie2 = cookie.Clone();

            cookie2.VerifySetDefaults(cookie2.Variant, uri, this.IsLocalDomain(uri.Host), this.m_fqdnMyDomain, true, true);
            this.Add(cookie2, true);
        }
All Usage Examples Of System.Net.Cookie::Clone