public bool Includes(MimeType other) { if (other == null) { return(false); } if (IsWildcardType) { // */* includes anything return(true); } else if (Type.Equals(other.Type)) { if (Subtype.Equals(other.Subtype)) { return(true); } if (IsWildcardSubtype) { // Wildcard with suffix, e.g. application/*+xml var thisPlusIdx = Subtype.LastIndexOf('+'); if (thisPlusIdx == -1) { return(true); } else { // application/*+xml includes application/soap+xml var otherPlusIdx = other.Subtype.LastIndexOf('+'); if (otherPlusIdx != -1) { var thisSubtypeNoSuffix = Subtype.Substring(0, thisPlusIdx); var thisSubtypeSuffix = Subtype.Substring(thisPlusIdx + 1); var otherSubtypeSuffix = other.Subtype.Substring(otherPlusIdx + 1); if (thisSubtypeSuffix.Equals(otherSubtypeSuffix) && WILDCARD_TYPE.Equals(thisSubtypeNoSuffix)) { return(true); } } } } } return(false); }
public bool IsCompatibleWith(MimeType other) { if (other == null) { return(false); } if (IsWildcardType || other.IsWildcardType) { return(true); } else if (Type.Equals(other.Type)) { if (Subtype.Equals(other.Subtype)) { return(true); } // Wildcard with suffix? e.g. application/*+xml if (IsWildcardSubtype || other.IsWildcardSubtype) { var thisPlusIdx = Subtype.LastIndexOf('+'); var otherPlusIdx = other.Subtype.LastIndexOf('+'); if (thisPlusIdx == -1 && otherPlusIdx == -1) { return(true); } else if (thisPlusIdx != -1 && otherPlusIdx != -1) { var thisSubtypeNoSuffix = Subtype.Substring(0, thisPlusIdx); var otherSubtypeNoSuffix = other.Subtype.Substring(0, otherPlusIdx); var thisSubtypeSuffix = Subtype.Substring(thisPlusIdx + 1); var otherSubtypeSuffix = other.Subtype.Substring(otherPlusIdx + 1); if (thisSubtypeSuffix.Equals(otherSubtypeSuffix) && (WILDCARD_TYPE.Equals(thisSubtypeNoSuffix) || WILDCARD_TYPE.Equals(otherSubtypeNoSuffix))) { return(true); } } } } return(false); }