Skip to content

Commit

Permalink
BHoM_Engine: Handle nulls
Browse files Browse the repository at this point in the history
  • Loading branch information
Fraser Greenroyd authored and adecler committed Apr 20, 2021
1 parent 80d6b73 commit 4736434
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
6 changes: 6 additions & 0 deletions BHoM_Engine/Query/Geometry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public static IGeometry IGeometry(this IBHoMObject obj)

public static IGeometry Geometry(this CustomObject obj)
{
if(obj == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the geometry of a null custom object.");
return null;
}

List<IGeometry> geometries = new List<IGeometry>();

foreach (object item in obj.CustomData.Values)
Expand Down
6 changes: 6 additions & 0 deletions BHoM_Engine/Query/Geometry3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ public static IGeometry IGeometry3D(this IObject obj)

public static IGeometry Geometry3D(this CustomObject obj)
{
if(obj == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the 3D Geometry of a null custom object.");
return null;
}

List<IGeometry> geometries = new List<IGeometry>();

foreach (object item in obj.CustomData.Values)
Expand Down
3 changes: 3 additions & 0 deletions BHoM_Engine/Query/GetAllFragments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public static partial class Query
[Output("fragmentList", "A deep copy of the fragments is returned for immutability.")]
public static List<IFragment> GetAllFragments(this IBHoMObject iBHoMObject, Type parentType = null)
{
if (iBHoMObject == null)
return new List<IFragment>();

List<IFragment> fragments = new List<IFragment>();

if (parentType == null)
Expand Down
6 changes: 6 additions & 0 deletions BHoM_Engine/Query/Hash.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ public static partial class Query
[Input("hashFromFragment", "If true, if the object is a BHoMObject storing a HashFragment, retrieve the hash from it instead of computing the hash.")]
public static string Hash(this IObject iObj, ComparisonConfig comparisonConfig = null, bool hashFromFragment = false)
{
if(iObj == null)
{
BH.Engine.Reflection.Compute.RecordError("Cannot query the hash of a null object.");
return "";
}

if (hashFromFragment && iObj is IBHoMObject)
{
// Instead of computing the Hash, first tryGet the hash in HashFragment
Expand Down
3 changes: 3 additions & 0 deletions BHoM_Engine/Query/UniquenessRestrictions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public static partial class Query
[Input("type", "The type of object you want to apply the fragment to.")]
public static List<Type> UniquenessRestrictions(this Type type)
{
if (type == null)
return new List<Type>();

// Do not cover value types
if (type.IsValueType)
return new List<Type>();
Expand Down

0 comments on commit 4736434

Please sign in to comment.