System.Net.Http.Headers.NameValueHeaderValue.Equals C# (CSharp) Method

Equals() public method

public Equals ( object obj ) : bool
obj object
return bool
        public override bool Equals(object obj)
        {
            NameValueHeaderValue other = obj as NameValueHeaderValue;

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

            if (!string.Equals(_name, other._name, StringComparison.OrdinalIgnoreCase))
            {
                return false;
            }

            // RFC2616: 14.20: unquoted tokens should use case-INsensitive comparison; quoted-strings should use
            // case-sensitive comparison. The RFC doesn't mention how to compare quoted-strings outside the "Expect"
            // header. We treat all quoted-strings the same: case-sensitive comparison. 

            if (string.IsNullOrEmpty(_value))
            {
                return string.IsNullOrEmpty(other._value);
            }

            if (_value[0] == '"')
            {
                // We have a quoted string, so we need to do case-sensitive comparison.
                return string.Equals(_value, other._value, StringComparison.Ordinal);
            }
            else
            {
                return string.Equals(_value, other._value, StringComparison.OrdinalIgnoreCase);
            }
        }

Usage Example

 public void Equals_NameUseDifferentCasing_ConsideredEqual()
 {
     NameValueHeaderValue nameValue1 = new NameValueHeaderValue("text");
     NameValueHeaderValue nameValue2 = new NameValueHeaderValue("TEXT");
     Assert.True(nameValue1.Equals(nameValue2), "text vs. TEXT.");
 }
All Usage Examples Of System.Net.Http.Headers.NameValueHeaderValue::Equals