PosInformatique.Foundations.MediaTypes
1.0.0
Prefix Reserved
See the version list below for details.
dotnet add package PosInformatique.Foundations.MediaTypes --version 1.0.0
NuGet\Install-Package PosInformatique.Foundations.MediaTypes -Version 1.0.0
<PackageReference Include="PosInformatique.Foundations.MediaTypes" Version="1.0.0" />
<PackageVersion Include="PosInformatique.Foundations.MediaTypes" Version="1.0.0" />
<PackageReference Include="PosInformatique.Foundations.MediaTypes" />
paket add PosInformatique.Foundations.MediaTypes --version 1.0.0
#r "nuget: PosInformatique.Foundations.MediaTypes, 1.0.0"
#:package PosInformatique.Foundations.MediaTypes@1.0.0
#addin nuget:?package=PosInformatique.Foundations.MediaTypes&version=1.0.0
#tool nuget:?package=PosInformatique.Foundations.MediaTypes&version=1.0.0
PosInformatique.Foundations.MediaTypes
Introduction
PosInformatique.Foundations.MediaTypes provides
a lightweight way to represent media types (MIME types) in .NET.
It offers an immutable MimeType value object, a set of well-known media types, helpers for mapping between
file extensions and media types, and a few convenience extension methods.
Install
You can install the package from NuGet:
dotnet add package PosInformatique.Foundations.MediaTypes
Features
- Immutable
MimeTypevalue object (type/subtype, e.g.application/json,image/png). - Parsing and safe parsing from
string(Parse/TryParse). - Provides
IFormattableandIParsable<T>for seamless integration with .NET APIs - Resolve a
MimeTypefrom a file extension (with or without leading dot). - Resolve a default file extension from a
MimeType. - Set of common
application/*andimage/*media types. - Simple extension methods, e.g.
IsPdf()andIsImage().
Usage
Parsing media types
using PosInformatique.Foundations.MediaTypes;
var json = MimeType.Parse("application/json");
Console.WriteLine(json.Type); // "application"
Console.WriteLine(json.Subtype); // "json"
if (MimeType.TryParse("image/png", out var png))
{
Console.WriteLine(png); // "image/png"
}
Well-known media types
using PosInformatique.Foundations.MediaTypes;
var pdf = MimeTypes.Application.Pdf; // application/pdf
var docx = MimeTypes.Application.Docx; // application/vnd.openxmlformats-officedocument.wordprocessingml.document
var jpeg = MimeTypes.Image.Jpeg; // image/jpeg
From file extension to media type
using PosInformatique.Foundations.MediaTypes;
var pdfFromExt = MimeType.FromExtension(".pdf"); // application/pdf
var pngFromExt = MimeType.FromExtension("png"); // image/png
// Unknown extensions fall back to application/octet-stream
var unknown = MimeType.FromExtension(".unknown"); // application/octet-stream
From media type to default file extension
using PosInformatique.Foundations.MediaTypes;
var pdf = MimeTypes.Application.Pdf;
var pdfExtension = pdf.GetExtension(); // ".pdf"
var webp = MimeTypes.Image.WebP;
var webpExtension = webp.GetExtension(); // ".webp"
Extension methods
using PosInformatique.Foundations.MediaTypes;
var mimeType = MimeTypes.Application.Pdf;
if (mimeType.IsPdf())
{
Console.WriteLine("This is a PDF document.");
}
var image = MimeTypes.Image.Png;
if (image.IsImage())
{
Console.WriteLine("This is an image type.");
}
var drawing = MimeTypes.Image.Dwg;
if (drawing.IsAutoCad())
{
Console.WriteLine("This is an AutoCAD drawing type.");
}
API overview
MimeType
- Immutable value object representing
type/subtype. - Implements
IEquatable<MimeType>andIParsable<MimeType>. - Main members:
string Type { get; }string Subtype { get; }static MimeType Parse(string s)static MimeType Parse(string s, IFormatProvider? provider)static bool TryParse(string? s, out MimeType? result)static bool TryParse(string? s, IFormatProvider? provider, out MimeType? result)static MimeType FromExtension(string extension)string GetExtension()
MimeTypes
Provides common media types and mapping helpers.
MimeTypes.ApplicationOctetStream(application/octet-stream)Pdf(application/pdf)Docx(application/vnd.openxmlformats-officedocument.wordprocessingml.document)
MimeTypes.ImageBmp(image/bmp)Dxf(image/x-dxf)Dwg(image/x-dwg)Jpeg(image/jpeg)Png(image/png)Tiff(image/tiff)WebP(image/webp)
MimeTypeExtensions
bool IsAutoCad(this MimeType mimeType)bool IsImage(this MimeType mimeType)bool IsPdf(this MimeType mimeType)
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on PosInformatique.Foundations.MediaTypes:
| Package | Downloads |
|---|---|
|
PosInformatique.Foundations.MediaTypes.Json
Provides a lightweight and immutable MimeType value object to represent media types (MIME types) in .NET. Includes parsing, safe parsing, well-known application/* and image/* media types, and helpers to map between file extensions and media types. |
|
|
PosInformatique.Foundations.MediaTypes.EntityFramework
Provides Entity Framework Core integration for the MimeType value object. Enables seamless mapping of MIME types as strongly-typed properties in Entity Framework Core entities, with safe conversion to string. |
|
|
PosInformatique.Foundations.Emailing
Provides a lightweight, template-based emailing infrastructure for .NET. Allows registering strongly-typed email templates, instantiating emails from models, and sending them through pluggable providers (e.g. Azure Communication Service). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.1.0-rc.2 | 53 | 1/26/2026 |
| 1.1.0-rc.1 | 61 | 1/23/2026 |
| 1.0.0 | 490 | 11/19/2025 |
| 1.0.0-rc.4 | 358 | 11/19/2025 |
| 1.0.0-rc.3 | 364 | 11/18/2025 |
| 1.0.0-rc.2 | 370 | 11/18/2025 |
| 1.0.0-rc.1 | 370 | 11/18/2025 |
1.0.0
- Initial release with strongly-typed MimeType value object.