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

Co-authored-by: TJ Lambert <tjlambert@microsoft.com>
This commit is contained in:
TJ Lambert 2022-05-05 10:42:02 -05:00 коммит произвёл GitHub
Родитель 1622221600
Коммит ac3f2ac642
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
9 изменённых файлов: 23 добавлений и 23 удалений

Просмотреть файл

@ -22,7 +22,7 @@ namespace SceneKit
public void AddAnimation (CAAnimation animation, string? key = null) 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); AddAnimation (animation, nskey);
nskey?.Dispose (); nskey?.Dispose ();

Просмотреть файл

@ -22,7 +22,7 @@ namespace SceneKit {
[Obsolete ("Use 'TimingFunction2' property.")] [Obsolete ("Use 'TimingFunction2' property.")]
public virtual Action<float>? TimingFunction { public virtual Action<float>? TimingFunction {
get { get {
if (TimingFunction2 == null) if (TimingFunction2 is null)
return null; return null;
else else
return (f) => { return (f) => {
@ -30,7 +30,7 @@ namespace SceneKit {
}; };
} }
set { set {
if (value == null) if (value is null)
TimingFunction2 = null; TimingFunction2 = null;
else else
TimingFunction2 = (f) => { TimingFunction2 = (f) => {
@ -76,7 +76,7 @@ namespace SceneKit {
[Mac (10, 9)] [Mac (10, 9)]
public virtual bool WriteToUrl (NSUrl url, SCNSceneLoadingOptions options, SCNSceneExportDelegate handler, SCNSceneExportProgressHandler exportProgressHandler) 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.")] [Obsolete ("Use the 'ISCNSceneExportDelegate' overload instead.")]
@ -134,7 +134,7 @@ namespace SceneKit {
static public void AddAnimation (this ISCNAnimatable self, SCNAnimation animation, string key) static public void AddAnimation (this ISCNAnimatable self, SCNAnimation animation, string key)
{ {
using (var ca = CAAnimation.FromSCNAnimation (animation)) 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); self.AddAnimation (ca, st);
} }
} }

Просмотреть файл

@ -22,7 +22,7 @@ namespace SceneKit {
public static unsafe SCNGeometrySource FromVertices (SCNVector3 [] vertices) public static unsafe SCNGeometrySource FromVertices (SCNVector3 [] vertices)
{ {
if (vertices == null) if (vertices is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (vertices)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (vertices));
fixed (SCNVector3 *ptr = &vertices [0]) fixed (SCNVector3 *ptr = &vertices [0])
@ -31,7 +31,7 @@ namespace SceneKit {
public static unsafe SCNGeometrySource FromNormals (SCNVector3 [] normals) public static unsafe SCNGeometrySource FromNormals (SCNVector3 [] normals)
{ {
if (normals == null) if (normals is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (normals)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (normals));
fixed (SCNVector3 *ptr = &normals[0]) fixed (SCNVector3 *ptr = &normals[0])
@ -40,7 +40,7 @@ namespace SceneKit {
public static unsafe SCNGeometrySource FromTextureCoordinates (CGPoint [] texcoords) public static unsafe SCNGeometrySource FromTextureCoordinates (CGPoint [] texcoords)
{ {
if (texcoords == null) if (texcoords is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (texcoords)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (texcoords));
fixed (CGPoint *ptr = &texcoords[0]) fixed (CGPoint *ptr = &texcoords[0])

Просмотреть файл

@ -35,7 +35,7 @@ namespace SceneKit
public static void ExportModule (JSContext context) public static void ExportModule (JSContext context)
{ {
if (context == null) if (context is null)
ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (context)); ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (context));
SCNExportJavaScriptModule (context.Handle); SCNExportJavaScriptModule (context.Handle);

Просмотреть файл

@ -30,7 +30,7 @@ namespace SceneKit
public void AddNodes (params SCNNode [] nodes) public void AddNodes (params SCNNode [] nodes)
{ {
if (nodes == null) if (nodes is null)
return; return;
foreach (var n in nodes) foreach (var n in nodes)
AddChildNode (n); AddChildNode (n);
@ -50,7 +50,7 @@ namespace SceneKit
#if !WATCH #if !WATCH
public void AddAnimation (CAAnimation animation, string? key) public void AddAnimation (CAAnimation animation, string? key)
{ {
if (key == null) { if (key is null) {
((ISCNAnimatable) this).AddAnimation (animation, (NSString?) null); ((ISCNAnimatable) this).AddAnimation (animation, (NSString?) null);
} else { } else {
using (var s = new NSString (key)) using (var s = new NSString (key))

Просмотреть файл

@ -43,7 +43,7 @@ namespace SceneKit
internal void Set (NSString key, SCNParticlePropertyController? value) internal void Set (NSString key, SCNParticlePropertyController? value)
{ {
if (mutDict == null){ if (mutDict is null){
mutDict = new NSMutableDictionary (dict); mutDict = new NSMutableDictionary (dict);
dict = mutDict; dict = mutDict;
} }
@ -183,7 +183,7 @@ namespace SceneKit
public SCNPropertyControllers? PropertyControllers { public SCNPropertyControllers? PropertyControllers {
get { get {
var weak = WeakPropertyControllers; var weak = WeakPropertyControllers;
if (weak == null) if (weak is null)
return null; return null;
return new SCNPropertyControllers (weak); return new SCNPropertyControllers (weak);
} }

Просмотреть файл

@ -21,10 +21,10 @@ namespace SceneKit
{ {
public static SCNPhysicsShape Create (SCNPhysicsShape [] shapes, SCNMatrix4 [] transforms) public static SCNPhysicsShape Create (SCNPhysicsShape [] shapes, SCNMatrix4 [] transforms)
{ {
if (shapes == null) if (shapes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (shapes)); ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (shapes));
if (transforms == null) if (transforms is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (transforms)); ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (transforms));
var t = new NSValue [transforms.Length]; var t = new NSValue [transforms.Length];
@ -38,10 +38,10 @@ namespace SceneKit
[Obsolete ("Use the 'Create' method that takes a 'SCNMatrix4 []'.")] [Obsolete ("Use the 'Create' method that takes a 'SCNMatrix4 []'.")]
public static SCNPhysicsShape Create (SCNPhysicsShape [] shapes, SCNVector3 [] transforms) public static SCNPhysicsShape Create (SCNPhysicsShape [] shapes, SCNVector3 [] transforms)
{ {
if (shapes == null) if (shapes is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (shapes)); ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (shapes));
if (transforms == null) if (transforms is null)
ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (transforms)); ObjCRuntime.ThrowHelper.ThrowArgumentException (nameof (transforms));
var t = new NSValue [transforms.Length]; var t = new NSValue [transforms.Length];
@ -89,7 +89,7 @@ namespace SceneKit
public SCNPhysicsShapeOptions? Options { public SCNPhysicsShapeOptions? Options {
get { get {
var o = _Options; var o = _Options;
if (o == null) if (o is null)
return null; return null;
return new SCNPhysicsShapeOptions (o); return new SCNPhysicsShapeOptions (o);
} }
@ -116,7 +116,7 @@ namespace SceneKit
internal SCNPhysicsShapeOptions (NSDictionary source) internal SCNPhysicsShapeOptions (NSDictionary source)
{ {
var ret = source [SCNPhysicsShapeOptionsKeys.Type] as NSString; var ret = source [SCNPhysicsShapeOptionsKeys.Type] as NSString;
if (ret != null){ if (ret is not null){
if (ret == SCNPhysicsShapeOptionsTypes.BoundingBox) if (ret == SCNPhysicsShapeOptionsTypes.BoundingBox)
ShapeType = SCNPhysicsShapeType.BoundingBox; ShapeType = SCNPhysicsShapeType.BoundingBox;
else if (ret == SCNPhysicsShapeOptionsTypes.ConcavePolyhedron) else if (ret == SCNPhysicsShapeOptionsTypes.ConcavePolyhedron)
@ -125,10 +125,10 @@ namespace SceneKit
ShapeType = SCNPhysicsShapeType.ConvexHull; ShapeType = SCNPhysicsShapeType.ConvexHull;
} }
var bret = source [SCNPhysicsShapeOptionsKeys.KeepAsCompound] as NSNumber; var bret = source [SCNPhysicsShapeOptionsKeys.KeepAsCompound] as NSNumber;
if (bret != null) if (bret is not null)
KeepAsCompound = bret.Int32Value != 0; KeepAsCompound = bret.Int32Value != 0;
var nret = source [SCNPhysicsShapeOptionsKeys.Scale] as NSValue; var nret = source [SCNPhysicsShapeOptionsKeys.Scale] as NSValue;
if (nret != null) if (nret is not null)
Scale = nret.Vector3Value; Scale = nret.Vector3Value;
} }

Просмотреть файл

@ -11,7 +11,7 @@ namespace SceneKit
public SCNRenderingApi? RenderingApi { public SCNRenderingApi? RenderingApi {
get { get {
var val = GetNUIntValue (SCNRenderingOptionsKeys.RenderingApiKey); var val = GetNUIntValue (SCNRenderingOptionsKeys.RenderingApiKey);
if (val != null) if (val is not null)
return (SCNRenderingApi)(uint) val; return (SCNRenderingApi)(uint) val;
return null; return null;
} }

Просмотреть файл

@ -42,7 +42,7 @@ namespace SceneKit {
for (nint i = 0; i < count; i++) { for (nint i = 0; i < count; i++) {
var item = NSValue.FromSCNMatrix4 (items [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); Marshal.WriteIntPtr (buf, (int)(i * IntPtr.Size), h);
} }