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

[quicklook] Add nullability to (generated and manual) bindings #14865

Merged
merged 5 commits into from
May 5, 2022
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/QuickLook/Thumbnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#nullable enable

#if MONOMAC

using System;
using System.Runtime.InteropServices;

Expand All @@ -43,20 +46,20 @@ public static partial class QLThumbnailImage {
[DllImport(Constants.QuickLookLibrary)]
extern static /* CGImageRef */ IntPtr QLThumbnailImageCreate (/* CFAllocatorRef */ IntPtr allocator, /* CFUrlRef */ IntPtr url, CGSize maxThumbnailSize, /* CFDictionaryRef */ IntPtr options);

public static CGImage Create (NSUrl url, CGSize maxThumbnailSize, float scaleFactor = 1, bool iconMode = false)
public static CGImage? Create (NSUrl url, CGSize maxThumbnailSize, float scaleFactor = 1, bool iconMode = false)
{
if (url == null)
throw new ArgumentNullException ("url");
if (url is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (url));

NSMutableDictionary dictionary = null;
NSMutableDictionary? dictionary = null;

if (scaleFactor != 1 && iconMode != false) {
dictionary = new NSMutableDictionary ();
dictionary.LowlevelSetObject ((NSNumber) scaleFactor, OptionScaleFactorKey.Handle);
dictionary.LowlevelSetObject (iconMode ? CFBoolean.TrueHandle : CFBoolean.FalseHandle, OptionIconModeKey.Handle);
}

var handle = QLThumbnailImageCreate (IntPtr.Zero, url.Handle, maxThumbnailSize, dictionary == null ? IntPtr.Zero : dictionary.Handle);
var handle = QLThumbnailImageCreate (IntPtr.Zero, url.Handle, maxThumbnailSize, dictionary is null ? IntPtr.Zero : dictionary.Handle);
Copy link
Member

Choose a reason for hiding this comment

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

This is simpler:

Suggested change
var handle = QLThumbnailImageCreate (IntPtr.Zero, url.Handle, maxThumbnailSize, dictionary is null ? IntPtr.Zero : dictionary.Handle);
var handle = QLThumbnailImageCreate (IntPtr.Zero, url.Handle, maxThumbnailSize, dictionary.GetHandle ());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the reminder!

GC.KeepAlive (dictionary);
if (handle != IntPtr.Zero)
return new CGImage (handle, true);
Expand Down