From 53c7bfa810b3a4b16fe308c51a509d5416056eec Mon Sep 17 00:00:00 2001 From: HavenDV Date: Sat, 29 Jun 2024 18:14:48 +0400 Subject: [PATCH 1/2] feat: Added nullable enable. --- MimeMapping.sln | 1 - src/MimeMapping/KnownMimeTypes.cs | 4 ++-- src/MimeMapping/KnownMimeTypes.tt | 4 ++-- src/MimeMapping/MimeMapping.csproj | 2 ++ src/MimeMapping/MimeUtility.cs | 14 +++++++------- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/MimeMapping.sln b/MimeMapping.sln index 0d598a6..16b13d1 100644 --- a/MimeMapping.sln +++ b/MimeMapping.sln @@ -6,7 +6,6 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{53C2C92A-AA91-4027-A6A3-AAECEE661B38}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig - MimeMapping.nuspec = MimeMapping.nuspec README.md = README.md EndProjectSection EndProject diff --git a/src/MimeMapping/KnownMimeTypes.cs b/src/MimeMapping/KnownMimeTypes.cs index d18b594..54008a7 100644 --- a/src/MimeMapping/KnownMimeTypes.cs +++ b/src/MimeMapping/KnownMimeTypes.cs @@ -7149,7 +7149,7 @@ public static class FileExtensions // Switch-case instead of dictionary since it does the hashing at compile time rather than run time - internal static string LookupType(string type) + internal static string? LookupType(string type) { switch (type) { @@ -10213,7 +10213,7 @@ internal static string LookupType(string type) } // Switch-case instead of dictionary since it does the hashing at compile time rather than run time - internal static string[] LookupMimeType(string mimeType) + internal static string[]? LookupMimeType(string mimeType) { switch (mimeType) { diff --git a/src/MimeMapping/KnownMimeTypes.tt b/src/MimeMapping/KnownMimeTypes.tt index e9c8d33..6bd9fab 100644 --- a/src/MimeMapping/KnownMimeTypes.tt +++ b/src/MimeMapping/KnownMimeTypes.tt @@ -155,7 +155,7 @@ namespace MimeMapping // Switch-case instead of dictionary since it does the hashing at compile time rather than run time - internal static string LookupType(string type) + internal static string? LookupType(string type) { switch (type) { @@ -181,7 +181,7 @@ namespace MimeMapping } // Switch-case instead of dictionary since it does the hashing at compile time rather than run time - internal static string[] LookupMimeType(string mimeType) + internal static string[]? LookupMimeType(string mimeType) { switch (mimeType) { diff --git a/src/MimeMapping/MimeMapping.csproj b/src/MimeMapping/MimeMapping.csproj index d871b31..f0b2313 100644 --- a/src/MimeMapping/MimeMapping.csproj +++ b/src/MimeMapping/MimeMapping.csproj @@ -3,6 +3,8 @@ netstandard2.0;net462 + enable + latest Constants for (almost) all MIME types and method to determine MIME type from a file name. Contains just over 1000 mime types. diff --git a/src/MimeMapping/MimeUtility.cs b/src/MimeMapping/MimeUtility.cs index 2da12ba..c452cc7 100644 --- a/src/MimeMapping/MimeUtility.cs +++ b/src/MimeMapping/MimeUtility.cs @@ -16,23 +16,23 @@ public static class MimeUtility /// public const string UnknownMimeType = "application/octet-stream"; - private static readonly Lazy> _lazyDictExtensions = new Lazy>( - () => new ReadOnlyDictionary(KnownMimeTypes.ALL_EXTS.Value.ToDictionary(e => e, e => KnownMimeTypes.LookupType(e))) + private static readonly Lazy> _lazyDictExtensions = new Lazy>( + () => new ReadOnlyDictionary(KnownMimeTypes.ALL_EXTS.Value.ToDictionary(e => e, e => KnownMimeTypes.LookupType(e))) ); - private static readonly Lazy> _lazyDictMimeTypes = new Lazy>( - () => new ReadOnlyDictionary(KnownMimeTypes.ALL_MIMETYPES.Value.Distinct().ToDictionary(e => e, e => KnownMimeTypes.LookupMimeType(e))) + private static readonly Lazy> _lazyDictMimeTypes = new Lazy>( + () => new ReadOnlyDictionary(KnownMimeTypes.ALL_MIMETYPES.Value.Distinct().ToDictionary(e => e, e => KnownMimeTypes.LookupMimeType(e))) ); /// /// Dictionary of all available types by extension (lazy loaded on first call) /// - public static ReadOnlyDictionary TypeMap => _lazyDictExtensions.Value; + public static ReadOnlyDictionary TypeMap => _lazyDictExtensions.Value; /// /// Dictionary of all available types by mimetype (lazy loaded on first call) /// - public static ReadOnlyDictionary TypeToExtensionsMap => _lazyDictMimeTypes.Value; + public static ReadOnlyDictionary TypeToExtensionsMap => _lazyDictMimeTypes.Value; /// The file extensions (ex: "zip"), the file name, or file path /// The mime type string, returns "application/octet-stream" if no known type was found @@ -53,7 +53,7 @@ public static string GetMimeMapping(string file) /// The mime type string, e.g. "application/json" /// One or more extensions matching the mime type or null if no match - public static string[] GetExtensions(string mimeType) + public static string[]? GetExtensions(string mimeType) { if (string.IsNullOrEmpty(mimeType)) throw new ArgumentNullException(mimeType); From 3d3460c6c9b84cdeb2d13966030de0fbbf30ed07 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Tue, 2 Jul 2024 21:16:02 +0400 Subject: [PATCH 2/2] fix: Revert. --- MimeMapping.sln | 1 + 1 file changed, 1 insertion(+) diff --git a/MimeMapping.sln b/MimeMapping.sln index 16b13d1..0d598a6 100644 --- a/MimeMapping.sln +++ b/MimeMapping.sln @@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{53C2C92A-AA91-4027-A6A3-AAECEE661B38}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig + MimeMapping.nuspec = MimeMapping.nuspec README.md = README.md EndProjectSection EndProject