private CacheControlHeaderValue(CacheControlHeaderValue source)
        {
            Debug.Assert(source != null);

            _noCache         = source._noCache;
            _noStore         = source._noStore;
            _maxAge          = source._maxAge;
            _sharedMaxAge    = source._sharedMaxAge;
            _maxStale        = source._maxStale;
            _maxStaleLimit   = source._maxStaleLimit;
            _minFresh        = source._minFresh;
            _noTransform     = source._noTransform;
            _onlyIfCached    = source._onlyIfCached;
            _publicField     = source._publicField;
            _privateField    = source._privateField;
            _mustRevalidate  = source._mustRevalidate;
            _proxyRevalidate = source._proxyRevalidate;

            if (source._noCacheHeaders != null)
            {
                foreach (var noCacheHeader in source._noCacheHeaders)
                {
                    NoCacheHeaders.Add(noCacheHeader);
                }
            }

            if (source._privateHeaders != null)
            {
                foreach (var privateHeader in source._privateHeaders)
                {
                    PrivateHeaders.Add(privateHeader);
                }
            }

            if (source._extensions != null)
            {
                foreach (var extension in source._extensions)
                {
                    Extensions.Add((NameValueHeaderValue)((ICloneable)extension).Clone());
                }
            }
        }
        public override bool Equals(object obj)
        {
            CacheControlHeaderValue other = obj as CacheControlHeaderValue;

            if (other == null)
            {
                return(false);
            }

            if ((_noCache != other._noCache) || (_noStore != other._noStore) || (_maxAge != other._maxAge) ||
                (_sharedMaxAge != other._sharedMaxAge) || (_maxStale != other._maxStale) ||
                (_maxStaleLimit != other._maxStaleLimit) || (_minFresh != other._minFresh) ||
                (_noTransform != other._noTransform) || (_onlyIfCached != other._onlyIfCached) ||
                (_publicField != other._publicField) || (_privateField != other._privateField) ||
                (_mustRevalidate != other._mustRevalidate) || (_proxyRevalidate != other._proxyRevalidate))
            {
                return(false);
            }

            if (!HeaderUtilities.AreEqualCollections(_noCacheHeaders, other._noCacheHeaders,
                                                     StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (!HeaderUtilities.AreEqualCollections(_privateHeaders, other._privateHeaders,
                                                     StringComparer.OrdinalIgnoreCase))
            {
                return(false);
            }

            if (!HeaderUtilities.AreEqualCollections(_extensions, other._extensions))
            {
                return(false);
            }

            return(true);
        }
        private static bool TrySetCacheControlValues(CacheControlHeaderValue cc,
                                                     List <NameValueHeaderValue> nameValueList)
        {
            foreach (NameValueHeaderValue nameValue in nameValueList)
            {
                bool   success = true;
                string name    = nameValue.Name.ToLowerInvariant();

                switch (name)
                {
                case noCacheString:
                    success = TrySetOptionalTokenList(nameValue, ref cc._noCache, ref cc._noCacheHeaders);
                    break;

                case noStoreString:
                    success = TrySetTokenOnlyValue(nameValue, ref cc._noStore);
                    break;

                case maxAgeString:
                    success = TrySetTimeSpan(nameValue, ref cc._maxAge);
                    break;

                case maxStaleString:
                    success = ((nameValue.Value == null) || TrySetTimeSpan(nameValue, ref cc._maxStaleLimit));
                    if (success)
                    {
                        cc._maxStale = true;
                    }
                    break;

                case minFreshString:
                    success = TrySetTimeSpan(nameValue, ref cc._minFresh);
                    break;

                case noTransformString:
                    success = TrySetTokenOnlyValue(nameValue, ref cc._noTransform);
                    break;

                case onlyIfCachedString:
                    success = TrySetTokenOnlyValue(nameValue, ref cc._onlyIfCached);
                    break;

                case publicString:
                    success = TrySetTokenOnlyValue(nameValue, ref cc._publicField);
                    break;

                case privateString:
                    success = TrySetOptionalTokenList(nameValue, ref cc._privateField, ref cc._privateHeaders);
                    break;

                case mustRevalidateString:
                    success = TrySetTokenOnlyValue(nameValue, ref cc._mustRevalidate);
                    break;

                case proxyRevalidateString:
                    success = TrySetTokenOnlyValue(nameValue, ref cc._proxyRevalidate);
                    break;

                case sharedMaxAgeString:
                    success = TrySetTimeSpan(nameValue, ref cc._sharedMaxAge);
                    break;

                default:
                    cc.Extensions.Add(nameValue);     // success is always true
                    break;
                }

                if (!success)
                {
                    return(false);
                }
            }

            return(true);
        }