-
Notifications
You must be signed in to change notification settings - Fork 554
Description
Xamarin.iOS|Mac bindings already support [NullAllowed]. This controls if null checks are generated inside (the body of) API bindings.
We often talked about doing more tooling but it did not yet materialize. Now the upcoming C# 8 supports nullability annotations so our attributes are even more useful - with even less work on our side (tooling wise).
Steps
[x] Add nullability support to xtrospection tests - so we know where our bindings are missing (or extra) [NullAllowed]. The results can be ignore until we're ready for the next step;
[ ] Fix bindings (taking care not to create a merge hell with other existing/upcoming work). This will also eliminate recurrent bugs when we're missing [NullAllowed] (since using null is not possible).
[x] Add C#8 nullability annotations to the generator
Example
This binding
[Export ("alertControllerWithTitle:message:preferredStyle:")]
UIAlertController Create ([NullAllowed] string title, [NullAllowed] string message, UIAlertControllerStyle preferredStyle);currently generate
[Export ("alertControllerWithTitle:message:preferredStyle:")]
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
public static UIAlertController Create (string title, string message, UIAlertControllerStyle preferredStyle)
{
global::UIKit.UIApplication.EnsureUIThread ();
var nstitle = NSString.CreateNative (title);
var nsmessage = NSString.CreateNative (message);
...
}but would now generate
[Export ("alertControllerWithTitle:message:preferredStyle:")]
[BindingImpl (BindingImplOptions.GeneratedCode | BindingImplOptions.Optimizable)]
public static UIAlertController Create (string? title, string? message, UIAlertControllerStyle preferredStyle)
{
global::UIKit.UIApplication.EnsureUIThread ();
var nstitle = NSString.CreateNative (title);
var nsmessage = NSString.CreateNative (message);
...
}note the extra ? on the parameter types