-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add System.Net.Mime.MediaTypeMap #121776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add System.Net.Mime.MediaTypeMap #121776
Conversation
|
Tagging subscribers to this area: @dotnet/ncl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
ManickaP
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Closes #121017