BHoM / BHoM_UI

GNU Lesser General Public License v3.0
9 stars 5 forks source link

`ExplodeCaller` throws exception if any one property of an object cannot be retrieved, preventing retrieval of other retrievable properties #423

Closed alelom closed 2 years ago

alelom commented 2 years ago

Description:

ExplodeCaller calls obj.PropertyValue(propertyName). This method itself is improvable, as it should probably not throw an exception and check if the property can be get with a parameterless GetProperty() or other similar scenarios where a property cannot be retrieved. For example, in PropertyValue() we are not guarding against Indexers, but in general it's not wise for the Explode not to guard against exceptions for individual property gets.

Suggestion

Regardless of the reason why exception is thrown, the Explode component should have a retrieval mechanism that is Exception resistant when looping and invoking PropertyValue() for individual properties. A single non-gettable property can now stop the run of ExplodeCaller, preventing the retrieval of other retrievable properties.

Steps to reproduce:

Use explode on an object that has some indexer.

Expected behaviour:

Explode should continue running, populating non-gettable properties with nulls.

Test file(s):

Copy the following and paste in an open GH canvas:

```xml 0 2 2 1 0 7 6ae73ccf-1367-453d-823f-29bf3c792080 Shaded 1 100;150;0;0 100;0;150;0 637064072939926790 ExecuteLocalScript.gh 0 -775 -2275 2.2537477 0 0 Bahnhofstrasse 28/6 6600 Reutte Austria Robert McNeel & Associates 2019 david@mcneel.com David Rutten 000-don't-call-me www.rhino3d.com 1 BH.UI.Grasshopper, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null 5.0.0.0 8bbd9f31-e1cd-fb1a-4588-730892e8d0cf BH.UI.Grasshopper 5.0.0.0 5 a9a8ebd2-fff5-4c44-a8f5-739736d129ba C# Script true A C#.NET scriptable component 16 78 30a795b7-f972-4788-83e5-255d9dfd5527 C# Script C# false C:\ProgramData\BHoM\Assemblies\BHoM.dll 1 A = new gna.SampleCollection<object>(); using System.Linq; using BH.oM.Base; namespace gna { public class SampleCollection<T> : IObject { // Declare an array to store the data elements. private List<T> arr = new List<T>(); public string SomeProp1 {get {return "SomeValue1"; } set {}} // Define the indexer to allow client code to use [] notation. public T this[int i] { get { return arr.ElementAtOrDefault(i); } set { arr[i] = value; } } public string SomeProp2 {get {return "SomeValue2"; } set {}} } } 508 1125 48 31 522 1141 true 0 1 8ec86459-bf01-4409-baee-174d0d2b13d0 Output parameter A 4895ce58-7f17-4974-8184-a36a5ab4e9b6 A A false 0 537 1127 17 27 545.5 1140.5 true 3647c48a-3322-476f-8b34-4011540ab916 8bbd9f31-e1cd-fb1a-4588-730892e8d0cf Explode { "SelectedItem" : null, "InputParams" : [{ "_t" : "BH.oM.UI.ParamInfo", "BHoM_Guid" : "669d783e-09b4-417b-b5cd-c124b579fdeb", "Name" : "object", "Fragments" : [], "Tags" : [], "CustomData" : { }, "DataType" : { "_t" : "System.Type", "Name" : "System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "_bhomVersion" : "5.3" }, "Description" : "Object to explode", "Kind" : "Input", "HasDefaultValue" : false, "DefaultValue" : null, "IsRequired" : true, "IsSelected" : true, "DefaultValueWarning" : "" }], "OutputParams" : [{ "_t" : "BH.oM.UI.ParamInfo", "BHoM_Guid" : "b9968caf-077c-4850-be74-f80d79634acd", "Name" : "SomeProp1", "Fragments" : [], "Tags" : [], "CustomData" : { }, "DataType" : { "_t" : "System.Type", "Name" : "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "_bhomVersion" : "5.3" }, "Description" : "", "Kind" : "Output", "HasDefaultValue" : false, "DefaultValue" : null, "IsRequired" : false, "IsSelected" : true, "DefaultValueWarning" : "" }, { "_t" : "BH.oM.UI.ParamInfo", "BHoM_Guid" : "8aedff4b-b7c7-4e63-8b59-95e74ad4641d", "Name" : "Item", "Fragments" : [], "Tags" : [], "CustomData" : { }, "DataType" : { "_t" : "System.Type", "Name" : "System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "_bhomVersion" : "5.3" }, "Description" : "", "Kind" : "Output", "HasDefaultValue" : false, "DefaultValue" : null, "IsRequired" : false, "IsSelected" : true, "DefaultValueWarning" : "" }, { "_t" : "BH.oM.UI.ParamInfo", "BHoM_Guid" : "76c0ae72-add0-4052-8255-8b9b5ffe55ba", "Name" : "SomeProp2", "Fragments" : [], "Tags" : [], "CustomData" : { }, "DataType" : { "_t" : "System.Type", "Name" : "System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "_bhomVersion" : "5.3" }, "Description" : "", "Kind" : "Output", "HasDefaultValue" : false, "DefaultValue" : null, "IsRequired" : false, "IsSelected" : true, "DefaultValueWarning" : "" }], "BHoM_Guid" : "12b4c80b-95bb-4aa2-9982-e76301231887", "_bhomVersion" : "5.3" } Explode an object into its properties 354e340d-8c78-4804-9ddc-cf561421c96a Explode Explode 615 1107 137 66 669 1140 true 1 d67b6cf3-37ea-438e-a6b4-2cc76b572658 3 3ede854e-c753-40eb-84cb-b48008f14fd4 d67b6cf3-37ea-438e-a6b4-2cc76b572658 3ede854e-c753-40eb-84cb-b48008f14fd4 Object to explode a73a0463-303c-403c-91aa-674b419f33d8 object object { "_t" : "System.Type", "Name" : "System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "_bhomVersion" : "5.3" } false 0 4895ce58-7f17-4974-8184-a36a5ab4e9b6 1 6a184b65-baa3-42d1-a548-3915b401de53 false 10000 617 1109 37 62 637 1140 true 5cc4d183-eb8c-44e2-8142-e1d98a4ffc49 SomeProp1 SomeProp1 true 0 684 1109 66 20 717 1119.333 true 9ee77ec6-a9a8-4eac-8966-14b9728cdb44 Item Item { "_t" : "System.Type", "Name" : "System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", "_bhomVersion" : "5.3" } true 0 0 6a184b65-baa3-42d1-a548-3915b401de53 false 10000 684 1129 66 21 717 1140 true 596c2159-515d-42df-8b7f-d7ac3cb1feff SomeProp2 SomeProp2 true 0 684 1150 66 21 717 1160.667 true 59e0b89a-e487-49f8-bab8-b5bab16be14c Panel A panel for custom notes and text values 14ebc5c8-2068-4424-bee5-17830d38887e Panel Should be "SomeValue1" false 0 5cc4d183-eb8c-44e2-8142-e1d98a4ffc49 1 Double click to edit panel content… 797 1062 208 44 0 0 0 797.3128 1062.846 true 255;255;250;90 false false true false false true 59e0b89a-e487-49f8-bab8-b5bab16be14c Panel A panel for custom notes and text values ee3c184b-cb49-47fa-9539-d8980a410e39 Panel Should be "SomeValue2" false 0 596c2159-515d-42df-8b7f-d7ac3cb1feff 1 Double click to edit panel content… 796 1163 208 45 0 0 0 796.6638 1163.805 true 255;255;250;90 false false true false false true 59e0b89a-e487-49f8-bab8-b5bab16be14c Panel A panel for custom notes and text values 7c229ee6-56e2-4457-ad40-48530f1946cb Panel Should be null false 0 9ee77ec6-a9a8-4eac-8966-14b9728cdb44 1 Double click to edit panel content… 797 1113 208 44 0 0 0 797.995 1113.667 true 255;255;250;90 false false true false false true ``` <\details>