src/packages/EmbedIO/MimeType.cs
/// <summary>
/// Determines whether the specified string is a valid MIME type or media range.
/// </summary>
/// <param name="value">The value.</param>
/// <param name="acceptMediaRange">If set to <see langword="true"/>, both media ranges
/// (e.g. <c>"text/*"</c>, <c>"*/*"</c>) and specific MIME types (e.g. <c>"text/html"</c>)
/// are considered valid; if set to <see langword="false"/>, only specific MIME types
/// are considered valid.</param>
/// <returns><see langword="true"/> if <paramref name="value"/> is valid,
/// according to the value of <paramref name="acceptMediaRange"/>;
/// otherwise, <see langword="false"/>.</returns>
Determines whether the specified string is a valid MIME type or media range.
Determines whether the specified string is a valid MIME type or media range .
public static bool IsMimeType(string value, bool acceptMediaRange)
        {
            if (string.IsNullOrEmpty(value))
                return false;
            var slashPos = value.IndexOf('/');
            if (slashPos < 0)
                return false;
            var isWildcardSubtype = false;
            var subtype = value.Substring(slashPos + 1);
            if (subtype == "*")
            {
                if (!acceptMediaRange)
                    return false;
                isWildcardSubtype = true;
            }
            else if (!Validate.IsRfc2616Token(subtype))
            {
                return false;
            }
            var type = value.Substring(0, slashPos);
            return type == "*"
                ? acceptMediaRange && isWildcardSubtype
                : Validate.IsRfc2616Token(type);
        }
public static bool IsMimeType ( string value , bool acceptMediaRange ) { if ( string . IsNullOrEmpty ( value ) ) return false ; var slashPos = value . IndexOf ( ' ' ) ; if ( slashPos < 0 ) return false ; var isWildcardSubtype = false ; var subtype = value . Substring ( slashPos + 1 ) ; if ( subtype == " " ) { if ( ! acceptMediaRange ) return false ; isWildcardSubtype = true ; } else if ( ! Validate . IsRfc2616Token ( subtype ) ) { return false ; } var type = value . Substring ( 0 , slashPos ) ; return type == " " ? acceptMediaRange && isWildcardSubtype : Validate . IsRfc2616Token ( type ) ; }
Determines whether the specified string is a valid MIME type or media range.
Determines whether the specified string is a valid MIME type or media range .
if  is valid,
according to the value of ;
otherwise, .
if is valid according to the value of ; otherwise .
value
string
None
acceptMediaRange
bool
If set to , both media ranges
(e.g. "text""*""text/html", only specific MIME types
are considered valid.
If set to both media ranges ( e . g . " text " " * " " text / html " only specific MIME types are considered valid .