1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 14:28:47 +00:00

fix: validate null arguments in X10D.Unity

The CA runs are really testing me today.
This commit is contained in:
Oliver Booth 2023-04-11 17:09:14 +01:00
parent 2e9f27b6b7
commit e6025b1a4c
No known key found for this signature in database
GPG Key ID: 20BEB9DC87961025
3 changed files with 54 additions and 0 deletions

View File

@ -14,8 +14,14 @@ public static class ComponentExtensions
/// <param name="component">The component whose child components to retrieve.</param>
/// <typeparam name="T">The type of the components to retrieve.</typeparam>
/// <returns>An array <typeparamref name="T" /> representing the child components.</returns>
/// <exception cref="ArgumentNullException"><paramref name="component" /> is <see langword="null" />.</exception>
public static T[] GetComponentsInChildrenOnly<T>(this Component component)
{
if (component == null)
{
throw new ArgumentNullException(nameof(component));
}
return component.gameObject.GetComponentsInChildrenOnly<T>();
}
}

View File

@ -14,8 +14,14 @@ public static class PolyhedronExtensions
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertex">The vertex to add.</param>
/// <exception cref="ArgumentNullException"><paramref name="polyhedron" /> is <see langword="null" />.</exception>
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
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertex">The vertex to add.</param>
/// <exception cref="ArgumentNullException"><paramref name="polyhedron" /> is <see langword="null" />.</exception>
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
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertices">The vertices to add.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="polyhedron" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="vertices" /> is <see langword="null" />.</para>
/// </exception>
public static void AddVertices(this Polyhedron polyhedron, IEnumerable<Vector3Int> 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
/// </summary>
/// <param name="polyhedron">The polyhedron whose vertices to update.</param>
/// <param name="vertices">The vertices to add.</param>
/// <exception cref="ArgumentNullException">
/// <para><paramref name="polyhedron" /> is <see langword="null" />.</para>
/// -or-
/// <para><paramref name="vertices" /> is <see langword="null" />.</para>
/// </exception>
public static void AddVertices(this Polyhedron polyhedron, IEnumerable<Vector3> 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);

View File

@ -13,8 +13,14 @@ public static class GameObjectExtensions
/// <param name="gameObject">The game object whose child components to retrieve.</param>
/// <typeparam name="T">The type of the components to retrieve.</typeparam>
/// <returns>An array <typeparamref name="T" /> representing the child components.</returns>
/// <exception cref="ArgumentNullException"><paramref name="gameObject" /> is <see langword="null" />.</exception>
public static T[] GetComponentsInChildrenOnly<T>(this GameObject gameObject)
{
if (gameObject == null)
{
throw new ArgumentNullException(nameof(gameObject));
}
Transform rootTransform = gameObject.transform;
var components = new List<T>(gameObject.GetComponentsInChildren<T>());