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

[systemconfiguration] Add nullability to (generated and manual) bindings #14903

Merged
merged 4 commits into from
May 18, 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
12 changes: 7 additions & 5 deletions src/SystemConfiguration/CaptiveNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
// Copyright 2012-2015 Xamarin Inc. All rights reserved.
//

#nullable enable

using System;
using System.Runtime.InteropServices;
using CoreFoundation;
Expand All @@ -26,15 +28,15 @@ public static partial class CaptiveNetwork {
#if !NET
[Obsolete ("Always return 'null'.")]
[Unavailable (PlatformName.TvOS)]
public static Foundation.NSString NetworkInfoKeyBSSID => null;
public static Foundation.NSString? NetworkInfoKeyBSSID => null;

[Obsolete ("Always return 'null'.")]
[Unavailable (PlatformName.TvOS)]
public static Foundation.NSString NetworkInfoKeySSID => null;
public static Foundation.NSString? NetworkInfoKeySSID => null;

[Obsolete ("Always return 'null'.")]
[Unavailable (PlatformName.TvOS)]
public static Foundation.NSString NetworkInfoKeySSIDData => null;
public static Foundation.NSString? NetworkInfoKeySSIDData => null;

[Obsolete ("Throw a 'NotSupportedException'.")]
[Unavailable (PlatformName.TvOS)]
Expand Down Expand Up @@ -81,7 +83,7 @@ public static partial class CaptiveNetwork {
#else
[Deprecated (PlatformName.iOS, 14,0)]
#endif
static public StatusCode TryCopyCurrentNetworkInfo (string interfaceName, out NSDictionary currentNetworkInfo)
static public StatusCode TryCopyCurrentNetworkInfo (string interfaceName, out NSDictionary? currentNetworkInfo)
{
using (var nss = new NSString (interfaceName)) {
var ni = CNCopyCurrentNetworkInfo (nss.Handle);
Expand Down Expand Up @@ -113,7 +115,7 @@ static public StatusCode TryCopyCurrentNetworkInfo (string interfaceName, out NS
#else
[Deprecated (PlatformName.iOS, 14,0, message: "Use 'NEHotspotNetwork.FetchCurrent' instead.")]
#endif
static public StatusCode TryGetSupportedInterfaces (out string[] supportedInterfaces)
static public StatusCode TryGetSupportedInterfaces (out string?[]? supportedInterfaces)
{
IntPtr array = CNCopySupportedInterfaces ();
if (array == IntPtr.Zero) {
Expand Down
16 changes: 9 additions & 7 deletions src/SystemConfiguration/NetworkReachability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ public sockaddr_in (IPAddress address)
switch (address.AddressFamily) {
case AddressFamily.InterNetwork:
sin_family = 2; // Address for IPv4
#pragma warning disable CS0618 // Type or member is obsolete
sin_addr = (int) address.Address;
#pragma warning restore CS0618 // Type or member is obsolete
break;
case AddressFamily.InterNetworkV6:
sin_family = 30; // Address for IPv6
Expand Down Expand Up @@ -138,7 +140,7 @@ static IntPtr CheckFailure (IntPtr handle)
static IntPtr Create (IPAddress ip)
{
if (ip is null)
throw new ArgumentNullException (nameof (ip));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (ip));

var s = new sockaddr_in (ip);
return CheckFailure (SCNetworkReachabilityCreateWithAddress (IntPtr.Zero, ref s));
Expand All @@ -152,7 +154,7 @@ public NetworkReachability (IPAddress ip)
static IntPtr Create (string address)
{
if (address is null)
throw new ArgumentNullException (nameof (address));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (address));

return CheckFailure (SCNetworkReachabilityCreateWithName (IntPtr.Zero, address));
}
Expand Down Expand Up @@ -265,7 +267,7 @@ public StatusCode SetNotification (Notification callback)

#if !NET
lock (typeof (NetworkReachability)){
if (callouth == null)
if (callouth is null)
callouth = Callback;
}
#endif
Expand Down Expand Up @@ -307,10 +309,10 @@ public StatusCode SetNotification (Notification callback)
public bool Schedule (CFRunLoop runLoop, string mode)
{
if (runLoop is null)
throw new ArgumentNullException (nameof (runLoop));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (runLoop));

if (mode is null)
throw new ArgumentNullException (nameof (mode));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (mode));

var modeHandle = CFString.CreateNative (mode);
try {
Expand All @@ -331,10 +333,10 @@ public bool Schedule ()
public bool Unschedule (CFRunLoop runLoop, string mode)
{
if (runLoop is null)
throw new ArgumentNullException (nameof (runLoop));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (runLoop));

if (mode is null)
throw new ArgumentNullException (nameof (mode));
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (mode));

var modeHandle = CFString.CreateNative (mode);
try {
Expand Down
4 changes: 3 additions & 1 deletion src/SystemConfiguration/StatusCodeError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// Copyright 2012, 2016 Xamarin Inc. All rights reserved.
//

#nullable enable

using System;
using System.Runtime.InteropServices;

Expand All @@ -23,7 +25,7 @@ public static class StatusCodeError
[DllImport (Constants.SystemConfigurationLibrary)]
extern static IntPtr /* const char* */ SCErrorString (int code);

public static string GetErrorDescription (StatusCode statusCode)
public static string? GetErrorDescription (StatusCode statusCode)
{
var ptr = SCErrorString ((int) statusCode);
return Marshal.PtrToStringAnsi (ptr);
Expand Down
2 changes: 2 additions & 0 deletions src/SystemConfiguration/SystemConfigurationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
// Copyright 2012 Xamarin Inc. All rights reserved.
//

#nullable enable

using System;

namespace SystemConfiguration {
Expand Down