public override bool Equals(object obj) { WarningHeaderValue other = obj as WarningHeaderValue; if (other == null) { return(false); } // 'agent' is a host/token, i.e. use case-insensitive comparison. Use case-sensitive comparison for 'text' // since it is a quoted string. if ((_code != other._code) || (!string.Equals(_agent, other._agent, StringComparison.OrdinalIgnoreCase)) || (!string.Equals(_text, other._text, StringComparison.Ordinal))) { return(false); } // We have a date set. Verify 'other' has also a date that matches our value. if (_date.HasValue) { return(other._date.HasValue && (_date.Value == other._date.Value)); } // We don't have a date. If 'other' has a date, we're not equal. return(!other._date.HasValue); }
private WarningHeaderValue(WarningHeaderValue source) { Debug.Assert(source != null); _code = source._code; _agent = source._agent; _text = source._text; _date = source._date; }
internal static int GetWarningLength(string input, int startIndex, out object parsedValue) { Debug.Assert(startIndex >= 0); parsedValue = null; if (string.IsNullOrEmpty(input) || (startIndex >= input.Length)) { return(0); } // Read <code> in '<code> <agent> <text> ["<date>"]' int code; int current = startIndex; if (!TryReadCode(input, ref current, out code)) { return(0); } // Read <agent> in '<code> <agent> <text> ["<date>"]' string agent; if (!TryReadAgent(input, current, ref current, out agent)) { return(0); } // Read <text> in '<code> <agent> <text> ["<date>"]' int textLength = 0; int textStartIndex = current; if (HttpRuleParser.GetQuotedStringLength(input, current, out textLength) != HttpParseResult.Parsed) { return(0); } current = current + textLength; // Read <date> in '<code> <agent> <text> ["<date>"]' DateTimeOffset?date = null; if (!TryReadDate(input, ref current, out date)) { return(0); } WarningHeaderValue result = new WarningHeaderValue(); result._code = code; result._agent = agent; result._text = input.Substring(textStartIndex, textLength); result._date = date; parsedValue = result; return(current - startIndex); }
public static bool TryParse(string input, out WarningHeaderValue parsedValue) { int index = 0; object output; parsedValue = null; if (GenericHeaderParser.SingleValueWarningParser.TryParseValue(input, null, ref index, out output)) { parsedValue = (WarningHeaderValue)output; return(true); } return(false); }