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

[printcore] Add nullability to (generated and manual) bindings #14856

Merged
merged 4 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions src/PrintCore/Defs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
//
// Copyright 2016 Microsoft Inc
//

#nullable enable

using System;
using System.Runtime.InteropServices;
using System.Threading;
Expand Down
24 changes: 12 additions & 12 deletions src/PrintCore/PrintCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public PMStatusCode SessionError {
public void AssignDefaultSettings (PMPrintSettings settings)
{
if (settings is null)
throw new ArgumentNullException (nameof (settings));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (settings));
PMSessionDefaultPrintSettings (Handle, settings.Handle);
}

Expand All @@ -125,7 +125,7 @@ public void AssignDefaultSettings (PMPrintSettings settings)
public void AssignDefaultPageFormat (PMPageFormat pageFormat)
{
if (pageFormat is null)
throw new ArgumentNullException (nameof (pageFormat));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (pageFormat));
PMSessionDefaultPageFormat (Handle, pageFormat.Handle);
}

Expand Down Expand Up @@ -156,7 +156,7 @@ public PMStatusCode CreatePrinterList (out string? []? printerList, out int inde
public PMStatusCode ValidatePrintSettings (PMPrintSettings settings, out bool changed)
{
if (settings is null)
throw new ArgumentNullException (nameof (settings));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (settings));

var code = PMSessionValidatePrintSettings (Handle, settings.Handle, out var c);
if (code != PMStatusCode.Ok){
Expand Down Expand Up @@ -255,7 +255,7 @@ public PMStatusCode SetPageRange (uint minPage, uint maxPage)
public PMStatusCode CopySettings (PMPrintSettings destination)
{
if (destination is null)
throw new ArgumentNullException (nameof (destination));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (destination));
return PMCopyPrintSettings (Handle, destination.Handle);
}

Expand Down Expand Up @@ -473,7 +473,7 @@ public PMPaperMargins? Margins {
public string? GetLocalizedName (PMPrinter printer)
{
if (printer is null)
throw new ArgumentNullException (nameof (printer));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (printer));
var code = PMPaperCreateLocalizedName (Handle, printer.Handle, out var name);
if (code != PMStatusCode.Ok)
return null;
Expand Down Expand Up @@ -511,7 +511,7 @@ public PMPrinter ()
static IntPtr Create (string printerId)
{
if (printerId is null)
throw new ArgumentNullException (nameof (printerId));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (printerId));

var printerIdHandle = CFString.CreateNative (printerId);
try {
Expand Down Expand Up @@ -647,9 +647,9 @@ public PMPaper [] PaperList {
public PMStatusCode TryPrintFile (PMPrintSettings settings, PMPageFormat? pageFormat, NSUrl fileUrl, string? mimeType = null)
{
if (settings is null)
throw new ArgumentNullException (nameof (settings));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (settings));
if (fileUrl is null)
throw new ArgumentNullException (nameof (fileUrl));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (fileUrl));

IntPtr mime = CFString.CreateNative (mimeType);
try {
Expand All @@ -665,9 +665,9 @@ public PMStatusCode TryPrintFile (PMPrintSettings settings, PMPageFormat? pageFo
public PMStatusCode TryPrintFromProvider (PMPrintSettings settings, PMPageFormat? pageFormat, CGDataProvider provider, string? mimeType = null)
{
if (settings is null)
throw new ArgumentNullException (nameof (settings));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (settings));
if (provider is null)
throw new ArgumentNullException (nameof (provider));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (provider));

IntPtr mime = CFString.CreateNative (mimeType);
try {
Expand All @@ -685,7 +685,7 @@ public PMStatusCode TryPrintFromProvider (PMPrintSettings settings, PMPageFormat
public PMResolution GetOutputResolution (PMPrintSettings settings)
{
if (settings is null)
throw new ArgumentNullException (nameof (settings));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (settings));

if (PMPrinterGetOutputResolution (Handle, settings.Handle, out var res) == PMStatusCode.Ok)
return res;
Expand All @@ -695,7 +695,7 @@ public PMResolution GetOutputResolution (PMPrintSettings settings)
public void SetOutputResolution (PMPrintSettings settings, PMResolution res)
{
if (settings is null)
throw new ArgumentNullException (nameof (settings));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (settings));
PMPrinterSetOutputResolution (Handle, settings.Handle, ref res);
}

Expand Down