From e6025b1a4cd6a188a358c150ec3e2e43bf835733 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Tue, 11 Apr 2023 17:09:14 +0100 Subject: [PATCH] fix: validate null arguments in X10D.Unity The CA runs are really testing me today. --- X10D.Unity/src/ComponentExtensions.cs | 6 +++ .../src/Drawing/PolyhedronExtensions.cs | 42 +++++++++++++++++++ X10D.Unity/src/GameObjectExtensions.cs | 6 +++ 3 files changed, 54 insertions(+) diff --git a/X10D.Unity/src/ComponentExtensions.cs b/X10D.Unity/src/ComponentExtensions.cs index 6ad7388..01d0a27 100644 --- a/X10D.Unity/src/ComponentExtensions.cs +++ b/X10D.Unity/src/ComponentExtensions.cs @@ -14,8 +14,14 @@ public static class ComponentExtensions /// The component whose child components to retrieve. /// The type of the components to retrieve. /// An array representing the child components. + /// is . public static T[] GetComponentsInChildrenOnly(this Component component) { + if (component == null) + { + throw new ArgumentNullException(nameof(component)); + } + return component.gameObject.GetComponentsInChildrenOnly(); } } diff --git a/X10D.Unity/src/Drawing/PolyhedronExtensions.cs b/X10D.Unity/src/Drawing/PolyhedronExtensions.cs index 108b9a8..94cd4ed 100644 --- a/X10D.Unity/src/Drawing/PolyhedronExtensions.cs +++ b/X10D.Unity/src/Drawing/PolyhedronExtensions.cs @@ -14,8 +14,14 @@ public static class PolyhedronExtensions /// /// The polyhedron whose vertices to update. /// The vertex to add. + /// is . public static void AddVertex(this Polyhedron polyhedron, Vector3Int vertex) { + if (polyhedron is null) + { + throw new ArgumentNullException(nameof(polyhedron)); + } + polyhedron.AddVertex(vertex.ToSystemVector()); } @@ -24,8 +30,14 @@ public static class PolyhedronExtensions /// /// The polyhedron whose vertices to update. /// The vertex to add. + /// is . public static void AddVertex(this Polyhedron polyhedron, Vector3 vertex) { + if (polyhedron is null) + { + throw new ArgumentNullException(nameof(polyhedron)); + } + polyhedron.AddVertex(vertex.ToSystemVector()); } @@ -34,8 +46,23 @@ public static class PolyhedronExtensions /// /// The polyhedron whose vertices to update. /// The vertices to add. + /// + /// is . + /// -or- + /// is . + /// public static void AddVertices(this Polyhedron polyhedron, IEnumerable vertices) { + if (polyhedron is null) + { + throw new ArgumentNullException(nameof(polyhedron)); + } + + if (vertices is null) + { + throw new ArgumentNullException(nameof(vertices)); + } + foreach (Vector3Int vertex in vertices) { polyhedron.AddVertex(vertex); @@ -47,8 +74,23 @@ public static class PolyhedronExtensions /// /// The polyhedron whose vertices to update. /// The vertices to add. + /// + /// is . + /// -or- + /// is . + /// public static void AddVertices(this Polyhedron polyhedron, IEnumerable vertices) { + if (polyhedron is null) + { + throw new ArgumentNullException(nameof(polyhedron)); + } + + if (vertices is null) + { + throw new ArgumentNullException(nameof(vertices)); + } + foreach (Vector3 vertex in vertices) { polyhedron.AddVertex(vertex); diff --git a/X10D.Unity/src/GameObjectExtensions.cs b/X10D.Unity/src/GameObjectExtensions.cs index 23d7f3c..559ee39 100644 --- a/X10D.Unity/src/GameObjectExtensions.cs +++ b/X10D.Unity/src/GameObjectExtensions.cs @@ -13,8 +13,14 @@ public static class GameObjectExtensions /// The game object whose child components to retrieve. /// The type of the components to retrieve. /// An array representing the child components. + /// is . public static T[] GetComponentsInChildrenOnly(this GameObject gameObject) { + if (gameObject == null) + { + throw new ArgumentNullException(nameof(gameObject)); + } + Transform rootTransform = gameObject.transform; var components = new List(gameObject.GetComponentsInChildren());