-
-
Notifications
You must be signed in to change notification settings - Fork 854
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
ImageFormatManager.TryFindFormatByFileExtension throws when null or whitespace is bad practice #2385
Comments
Yep. That guard should be removed, and null handled by assigning format to null and returning false. I wouldn't use a try/catch there. Feel free to open a PR if you have the time. |
@JimBobSquarePants I appreciate your swift response James. The try-catch was a crude example, I would never had intended to suggest that as a real-world fix/suggestion, just to illustrate my point. One of my colleagues will be submitting a PR for this. Best, |
Legend! Thanks |
ISSUE #2385 - Implementing try get pattern to TryFindFormatByFileExtension(string extension, [NotNullWhen(true)] out IImageFormat? format)
Fixed via #2386 |
Prerequisites
DEBUG
andRELEASE
modeImageSharp version
3.0.0
Other ImageSharp packages and versions
n/a
Environment (Operating system, version and so on)
Windows 10 & 11, 64bit, build 22000.1574
.NET Framework version
.NET 7
Description
The "ImageFormatManager.TryFindFormatByFileExtension" method here throws, which is against the TryX pattern.
What you'd expect is that methods beginning with TryXXXX would never throw and instead simply return false.
Crude example but;
It should be the responsibility of the consuming application to ensure that it has thoroughly tested its implementation of this method.
Steps to Reproduce
Images
No response
The text was updated successfully, but these errors were encountered: