Content TypeTry Parse(String, Content Type) Method
Try to parse the given text into a new ContentType instance.
Definition
Namespace: MimeKit
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
if the content type was successfully parsed; otherwise, .
Assembly: MimeKit.Core (in MimeKit.Core.dll) Version: 5.0.0
C#
public static bool TryParse(
string? text,
out ContentType?? type
)Parameters
- text String
- The text to parse.
- type ContentType
- The parsed content type.
Return Value
Booleanif the content type was successfully parsed; otherwise, .
Remarks
Parses a Content-Type value from the specified text.
Example
C#
public static void ParseContentType ()
{
// Parse() throws a ParseException if the text cannot be parsed.
var contentType = ContentType.Parse ("text/plain; charset=\"iso-8859-1\"; format=flowed");
Console.WriteLine ("MimeType: {0}", contentType.MimeType); // text/plain
Console.WriteLine ("MediaType: {0}", contentType.MediaType); // text
Console.WriteLine ("MediaSubtype: {0}", contentType.MediaSubtype); // plain
Console.WriteLine ("Charset: {0}", contentType.Charset); // iso-8859-1
Console.WriteLine ("Format: {0}", contentType.Format); // flowed
// TryParse() can be used instead when the value comes from an untrusted source.
if (ContentType.TryParse ("application/octet-stream; name=\"data.bin\"", out var type))
Console.WriteLine ("Name: {0}", type.Name); // data.bin
}