Skip to content
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

Remove some nullable disable comments #2312

Merged
merged 11 commits into from
Jan 10, 2023
Merged

Remove some nullable disable comments #2312

merged 11 commits into from
Jan 10, 2023

Conversation

stefannikolei
Copy link
Contributor

@stefannikolei stefannikolei commented Jan 1, 2023

#2231

Removed the nullable disable in all places where fixing it was an easy task

@stefannikolei
Copy link
Contributor Author

After these only 10 files have the annotation nullable disable

@@ -27,7 +27,7 @@ public static IImageEncoder DetectEncoder(this Image source, string filePath)
Guard.NotNull(filePath, nameof(filePath));

string ext = Path.GetExtension(filePath);
IImageFormat format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext);
IImageFormat? format = source.GetConfiguration().ImageFormatsManager.FindFormatByFileExtension(ext);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah... This is one of the areas I want to have a look at. Ideally this method should be rewritten to use the try-out pattern.

e.g

bool ImageFormatsManager.TryFindFormatByFileExtension(ext, [NotNullWhen(true)] out IImageFormat? format)

We'd return named tuples for async equivalents.

Copy link
Contributor Author

@stefannikolei stefannikolei Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok gonna have a look if I can easily rewrite that to this pattern

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legend. Thanks! It's something I very much wish we'd done from the start.

src/ImageSharp/Formats/Bmp/BmpImageFormatDetector.cs Outdated Show resolved Hide resolved
src/ImageSharp/Formats/ImageFormatManager.cs Outdated Show resolved Hide resolved
@JimBobSquarePants JimBobSquarePants added API codequality breaking Signifies a binary breaking change. labels Jan 4, 2023
@@ -27,7 +26,7 @@ public static IImageFormat DetectFormat(ReadOnlySpan<byte> data)
/// <param name="data">The byte span containing encoded image data to read the header from.</param>
/// <exception cref="ArgumentNullException">The options are null.</exception>
/// <returns>The mime type or null if none found.</returns>
public static IImageFormat DetectFormat(DecoderOptions options, ReadOnlySpan<byte> data)
public static IImageFormat? DetectFormat(DecoderOptions options, ReadOnlySpan<byte> data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to convert this and above to use the Try...Out pattern

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to convert InternalDetectFormat from Image.Decode.cs to the Try Pattern or just return IImageFormat?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally it should use the Try pattern all the way down.

Copy link
Contributor Author

@stefannikolei stefannikolei Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And at this Point it gets tricky. In Order to do this I have to also touch 'DiscoverDecoder' this already has IImageFormat as out parameter. When trying to refactor this to the try pattern we are in a situation where one ore the other could be null :(

What do you think if we change the implementation here tho that a format must be passed to DiscoverDecoder?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a second look and we wouldn't be able to adopt the Try pattern there actually. The method is used within a lambda which doesn't allow ref or out parameters..

@stefannikolei
Copy link
Contributor Author

After these only 10 files have the annotation nullable disable

Ok i have no clue how I searched. In total there a more nullable disable in the Solution.. Probably I searched while in a specific scope ... oO

Copy link
Member

@JimBobSquarePants JimBobSquarePants left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good to merge for now. Thanks!

I want to have a discussion about how to handle the various Image.Load APIs next.

@JimBobSquarePants JimBobSquarePants merged commit f1968ba into SixLabors:main Jan 10, 2023
@stefannikolei stefannikolei deleted the stefannikolei/nullable branch January 17, 2023 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API breaking Signifies a binary breaking change. codequality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants