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

BHoM_Engine: Handle nulls #2476

Merged
merged 1 commit into from
Apr 20, 2021
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
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