Creating custom OutputFormatters
The plan is to create a VCard output to be able to import the person's contact details directly to Outlook or any other contact database that supports VCards. Later in this section, we also want to create a CSV output formatter.
Both are text-based output formatters and will derive their values from TextOutputFormatter
:
- Create a new class in a new file called
VcardOutputFormatter.cs
. - Now, insert the following class skeleton in the new file. You will find the implementations of the empty methods in the following snippets. The constructor contains the supported media types and content encodings:
public class VcardOutputFormatter : TextOutputFormatter { Â Â Â Â public string ContentType { get; } Â Â Â Â public VcardOutputFormatter() Â Â Â Â { Â Â Â Â Â Â Â Â SupportedMediaTypes.Add( Â Â Â Â Â Â Â Â Â Â Â Â MediaTypeHeaderValue...