diff --git a/src/ImageSharp/Formats/ImageFormatManager.cs b/src/ImageSharp/Formats/ImageFormatManager.cs index eeb1ebf8d4..3969693d64 100644 --- a/src/ImageSharp/Formats/ImageFormatManager.cs +++ b/src/ImageSharp/Formats/ImageFormatManager.cs @@ -91,9 +91,13 @@ public class ImageFormatManager /// /// For the specified file extensions type find the e . /// - /// The extension to discover - /// The if found otherwise null - /// False if no format was found + /// The extension to return the format for. + /// + /// When this method returns, contains the format that matches the given extension; + /// otherwise, the default value for the type of the parameter. + /// This parameter is passed uninitialized. + /// . + /// if a match is found; otherwise, public bool TryFindFormatByFileExtension(string extension, [NotNullWhen(true)] out IImageFormat? format) { Guard.NotNullOrWhiteSpace(extension, nameof(extension)); @@ -106,16 +110,24 @@ public class ImageFormatManager format = this.imageFormats.FirstOrDefault(x => x.FileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase)); - return format != null; + return format is not null; } /// /// For the specified mime type find the . /// - /// The mime-type to discover - /// The if found; otherwise null - public IImageFormat? FindFormatByMimeType(string mimeType) - => this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase)); + /// The mime-type to return the format for. + /// + /// When this method returns, contains the format that matches the given mime-type; + /// otherwise, the default value for the type of the parameter. + /// This parameter is passed uninitialized. + /// . + /// if a match is found; otherwise, + public bool TryFindFormatByMimeType(string mimeType, [NotNullWhen(true)] out IImageFormat? format) + { + format = this.imageFormats.FirstOrDefault(x => x.MimeTypes.Contains(mimeType, StringComparer.OrdinalIgnoreCase)); + return format is not null; + } internal IImageFormat? FindFormatByDecoder(IImageDecoder decoder) => this.mimeTypeDecoders.FirstOrDefault(x => x.Value.GetType() == decoder.GetType()).Key;