Add System.Net.Mime.MediaTypeMap#121776
Merged
stephentoub merged 3 commits intodotnet:mainfrom Nov 27, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds a new MediaTypeMap class to the System.Net.Mime namespace that provides bidirectional mapping between file extensions and media types (MIME types). The implementation includes comprehensive mappings for 429 extensions to media types and 278 media types to extensions, supporting common scenarios like determining content types for email attachments or web responses.
- Adds static methods for converting file paths/extensions to media types and vice versa
- Includes both string and ReadOnlySpan overloads for performance
- Provides extensive test coverage for various edge cases and common scenarios
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/libraries/System.Net.Mail/src/System/Net/Mime/MediaTypeMap.cs | New class implementing bidirectional mapping with 429 extension→media type and 278 media type→extension mappings using Dictionary AlternateLookup for efficient span-based lookups |
| src/libraries/System.Net.Mail/src/System.Net.Mail.csproj | Registers the new MediaTypeMap.cs file in the project |
| src/libraries/System.Net.Mail/ref/System.Net.Mail.cs | Adds public API surface for the four MediaTypeMap methods (string and span overloads for GetMediaType and GetExtension) |
| src/libraries/System.Net.Mail/tests/Functional/MediaTypeMapTest.cs | Comprehensive test suite covering null handling, unknown values, case-insensitivity, parameter stripping, round-trip conversions, and whitespace handling |
| src/libraries/System.Net.Mail/tests/Functional/System.Net.Mail.Functional.Tests.csproj | Registers the new test file in the test project |
am11
reviewed
Nov 19, 2025
MihaZupan
approved these changes
Nov 24, 2025
src/libraries/System.Net.Mail/src/System/Net/Mime/MediaTypeMap.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.Net.Mail/src/System/Net/Mime/MediaTypeMap.cs
Outdated
Show resolved
Hide resolved
And iterated with copilot on the mappings.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #121017