MimeTypeToString(MimeFormats, Int32) Method

Serializes the instance as Internet Media Type String ("MIME type") with several options.

Definition

Namespace: FolkerKinzel.MimeTypes
Assembly: FolkerKinzel.MimeTypes (in FolkerKinzel.MimeTypes.dll) Version: 1.0.0+7dd5ca03f25d4802263abb2083f9c7add2cb51ec
C#
public string ToString(
	MimeFormats options,
	int lineLength = 64
)

Parameters

options  MimeFormats
Named constants to specify options for the serialization of the instance. The flags can be combined.
lineLength  Int32  (Optional)
The number of characters in a single line of the serialized instance before a line-wrapping occurs. The parameter is ignored, if the flag LineWrapping is not set. If the value of the argument is smaller than MinLineLength, the value of MinLineLength is taken instead.

Return Value

String
A String representation of the instance according to RFC 2045 and RFC 2231.

Example

Formatting a MimeType instance into a standards-compliant String using several options:

C#
using FolkerKinzel.MimeTypes;

namespace Examples;

public static class FormattingOptionsExample
{
    public static void Example()
    {
        MimeType mimeType =
            MimeType.Create("application", "x-stuff")
                           .AppendParameter("short", "s")
                           .AppendParameter("key-long",
            "Very very loooong value in order to show the line wrapping");

        Console.WriteLine("MimeFormats.Default:");
        Console.WriteLine(mimeType.ToString());
        Console.WriteLine();

        Console.WriteLine("MimeFormats.IgnoreParameters:");
        Console.WriteLine(mimeType.ToString(MimeFormats.IgnoreParameters));
        Console.WriteLine();

        Console.WriteLine("MimeFormats.AvoidSpace:");
        Console.WriteLine(mimeType.ToString(MimeFormats.AvoidSpace));
        Console.WriteLine();

        Console.WriteLine("MimeFormats.LineWrapping:");
        Console.WriteLine(mimeType.ToString(MimeFormats.LineWrapping));
        Console.WriteLine();

        Console.WriteLine("MimeFormats.LineWrapping | MimeFormats.AvoidSpace:");
        Console.WriteLine(mimeType.ToString(MimeFormats.LineWrapping | MimeFormats.AvoidSpace));
        Console.WriteLine();

        Console.WriteLine("MimeFormats.Url:");
        Console.WriteLine(mimeType.ToString(MimeFormats.Url));
        Console.WriteLine();
    }
}

/*
Console Output:

MimeFormats.Default:
application/x-stuff; short=s; key-long="Very very loooong value in order to show the line wrapping"

MimeFormats.IgnoreParameters:
application/x-stuff

MimeFormats.AvoidSpace:
application/x-stuff;short=s;key-long="Very very loooong value in order to show the line wrapping"

MimeFormats.LineWrapping:
application/x-stuff; short=s;
key-long*0="Very very loooong value in order to show the line ";
key-long*1="wrapping"

MimeFormats.LineWrapping | MimeFormats.AvoidSpace:
application/x-stuff;short=s;
key-long*0="Very very loooong value in order to show the line ";
key-long*1="wrapping"

MimeFormats.Url:
application/x-stuff;short=s;key-long*=utf-8''Very%20very%20loooong%20value%20in%20order%20to%20show%20the%20line%20wrapping
*/

See Also