System.Net.Http.Headers.CookieHeaderValue.TryParse C# (CSharp) Method

TryParse() public static method

public static TryParse ( string input, CookieHeaderValue &parsedValue ) : bool
input string
parsedValue CookieHeaderValue
return bool
        public static bool TryParse(string input, out CookieHeaderValue parsedValue)
        {
            parsedValue = null;
            if (!String.IsNullOrEmpty(input))
            {
                string[] segments = input.Split(segmentSeparator);
                CookieHeaderValue instance = new CookieHeaderValue();
                foreach (string segment in segments)
                {
                    if (!ParseCookieSegment(instance, segment))
                    {
                        return false;
                    }
                }

                // If we didn't find any cookie state name/value pairs then cookie is not valid
                if (instance.Cookies.Count == 0)
                {
                    return false;
                }

                parsedValue = instance;
                return true;
            }

            return false;
        }

Usage Example

Esempio n. 1
0
        public void CookieHeaderValue_TryParse_RejectsInvalidValues(string value)
        {
            CookieHeaderValue header;
            bool result = CookieHeaderValue.TryParse(value, out header);

            Assert.False(result);
        }
All Usage Examples Of System.Net.Http.Headers.CookieHeaderValue::TryParse