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

[scenekit] Add nullability to (generated and manual) bindings #14879

Merged
merged 2 commits into from
May 5, 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
2 changes: 1 addition & 1 deletion src/SceneKit/SCNAnimatable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class SCNAnimatable {

public void AddAnimation (CAAnimation animation, string? key = null)
{
var nskey = key == null ? null : new NSString (key);
var nskey = key is null ? null : new NSString (key);

AddAnimation (animation, nskey);
nskey?.Dispose ();
Expand Down
8 changes: 4 additions & 4 deletions src/SceneKit/SCNCompat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ partial class SCNAction {
[Obsolete ("Use 'TimingFunction2' property.")]
public virtual Action<float>? TimingFunction {
get {
if (TimingFunction2 == null)
if (TimingFunction2 is null)
return null;
else
return (f) => {
TimingFunction2 (f);
};
}
set {
if (value == null)
if (value is null)
TimingFunction2 = null;
else
TimingFunction2 = (f) => {
Expand Down Expand Up @@ -76,7 +76,7 @@ partial class SCNScene {
[Mac (10, 9)]
public virtual bool WriteToUrl (NSUrl url, SCNSceneLoadingOptions options, SCNSceneExportDelegate handler, SCNSceneExportProgressHandler exportProgressHandler)
{
return WriteToUrl (url: url, options: options == null ? null : options.Dictionary, aDelegate: handler, exportProgressHandler: exportProgressHandler);
return WriteToUrl (url: url, options: options?.Dictionary, aDelegate: handler, exportProgressHandler: exportProgressHandler);
}

[Obsolete ("Use the 'ISCNSceneExportDelegate' overload instead.")]
Expand Down Expand Up @@ -134,7 +134,7 @@ static public partial class SCNAnimatableExtensions {
static public void AddAnimation (this ISCNAnimatable self, SCNAnimation animation, string key)
{
using (var ca = CAAnimation.FromSCNAnimation (animation))
using (var st = key != null ? new NSString (key) : null)
using (var st = key is not null ? new NSString (key) : null)
self.AddAnimation (ca, st);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/SceneKit/SCNGeometrySource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public partial class SCNGeometrySource {

public static unsafe SCNGeometrySource FromVertices (SCNVector3 [] vertices)
{
if (vertices == null)
if (vertices is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (vertices));

fixed (SCNVector3 *ptr = &vertices [0])
Expand All @@ -31,7 +31,7 @@ public static unsafe SCNGeometrySource FromVertices (SCNVector3 [] vertices)

public static unsafe SCNGeometrySource FromNormals (SCNVector3 [] normals)
{
if (normals == null)
if (normals is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (normals));

fixed (SCNVector3 *ptr = &normals[0])
Expand All @@ -40,7 +40,7 @@ public static unsafe SCNGeometrySource FromNormals (SCNVector3 [] normals)

public static unsafe SCNGeometrySource FromTextureCoordinates (CGPoint [] texcoords)
{
if (texcoords == null)
if (texcoords is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (texcoords));

fixed (CGPoint *ptr = &texcoords[0])
Expand Down
2 changes: 1 addition & 1 deletion src/SceneKit/SCNJavaScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static class SCNJavaScript

public static void ExportModule (JSContext context)
{
if (context == null)
if (context is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (context));

SCNExportJavaScriptModule (context.Handle);
Expand Down
4 changes: 2 additions & 2 deletions src/SceneKit/SCNNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void Add (SCNNode node)

public void AddNodes (params SCNNode [] nodes)
{
if (nodes == null)
if (nodes is null)
return;
foreach (var n in nodes)
AddChildNode (n);
Expand All @@ -50,7 +50,7 @@ IEnumerator IEnumerable.GetEnumerator ()
#if !WATCH
public void AddAnimation (CAAnimation animation, string? key)
{
if (key == null) {
if (key is null) {
((ISCNAnimatable) this).AddAnimation (animation, (NSString?) null);
} else {
using (var s = new NSString (key))
Expand Down
4 changes: 2 additions & 2 deletions src/SceneKit/SCNParticleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public SCNPropertyControllers ()

internal void Set (NSString key, SCNParticlePropertyController? value)
{
if (mutDict == null){
if (mutDict is null){
mutDict = new NSMutableDictionary (dict);
dict = mutDict;
}
Expand Down Expand Up @@ -183,7 +183,7 @@ public partial class SCNParticleSystem
public SCNPropertyControllers? PropertyControllers {
get {
var weak = WeakPropertyControllers;
if (weak == null)
if (weak is null)
return null;
return new SCNPropertyControllers (weak);
}
Expand Down
16 changes: 8 additions & 8 deletions src/SceneKit/SCNPhysicsShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public partial class SCNPhysicsShape
{
public static SCNPhysicsShape Create (SCNPhysicsShape [] shapes, SCNMatrix4 [] transforms)
{
if (shapes == null)
if (shapes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (shapes));

if (transforms == null)
if (transforms is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (transforms));

var t = new NSValue [transforms.Length];
Expand All @@ -38,10 +38,10 @@ public static SCNPhysicsShape Create (SCNPhysicsShape [] shapes, SCNMatrix4 [] t
[Obsolete ("Use the 'Create' method that takes a 'SCNMatrix4 []'.")]
public static SCNPhysicsShape Create (SCNPhysicsShape [] shapes, SCNVector3 [] transforms)
{
if (shapes == null)
if (shapes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (shapes));

if (transforms == null)
if (transforms is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (transforms));

var t = new NSValue [transforms.Length];
Expand Down Expand Up @@ -89,7 +89,7 @@ public static SCNPhysicsShape Create (SCNNode node, SCNPhysicsShapeOptions? opti
public SCNPhysicsShapeOptions? Options {
get {
var o = _Options;
if (o == null)
if (o is null)
return null;
return new SCNPhysicsShapeOptions (o);
}
Expand All @@ -116,7 +116,7 @@ public SCNPhysicsShapeOptions () {}
internal SCNPhysicsShapeOptions (NSDictionary source)
{
var ret = source [SCNPhysicsShapeOptionsKeys.Type] as NSString;
if (ret != null){
if (ret is not null){
if (ret == SCNPhysicsShapeOptionsTypes.BoundingBox)
ShapeType = SCNPhysicsShapeType.BoundingBox;
else if (ret == SCNPhysicsShapeOptionsTypes.ConcavePolyhedron)
Expand All @@ -125,10 +125,10 @@ internal SCNPhysicsShapeOptions (NSDictionary source)
ShapeType = SCNPhysicsShapeType.ConvexHull;
}
var bret = source [SCNPhysicsShapeOptionsKeys.KeepAsCompound] as NSNumber;
if (bret != null)
if (bret is not null)
KeepAsCompound = bret.Int32Value != 0;
var nret = source [SCNPhysicsShapeOptionsKeys.Scale] as NSValue;
if (nret != null)
if (nret is not null)
Scale = nret.Vector3Value;
}

Expand Down
2 changes: 1 addition & 1 deletion src/SceneKit/SCNRenderingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public partial class SCNRenderingOptions {
public SCNRenderingApi? RenderingApi {
get {
var val = GetNUIntValue (SCNRenderingOptionsKeys.RenderingApiKey);
if (val != null)
if (val is not null)
return (SCNRenderingApi)(uint) val;
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion src/SceneKit/SCNSkinner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ static NSArray ToNSArray (SCNMatrix4 []? items)

for (nint i = 0; i < count; i++) {
var item = NSValue.FromSCNMatrix4 (items [i]);
var h = item == null ? NSNull.Null.Handle : item.Handle;
var h = item?.Handle ?? NSNull.Null.Handle;
Marshal.WriteIntPtr (buf, (int)(i * IntPtr.Size), h);
}

Expand Down