Severity - Fail
Check method - Here
HasValidConstructor check ensures that any BHoM object which implements a constructor with parameters contains all of the parameters it requires to satisfy the Serialisation requirement.
Constructors should only exist on objects implementing the
IImmutable interface. Objects with this interface should have properties which are
get only (no
set accessor). All of these
get only properties should be parameters to the constructor, with the parameter name matching the property name following the usual lowercase conventions for parameter names.
Consider the following
IImmutable object, which does not have a constructor.
This object will not correctly deserialise, as it will not be able to adequately set the properties
MyString. Therefore, a constructor must be provided with the parameter names matching, so the deserialisation can correctly align the deserialised data to the object property.
MyPoint does not have to be a parameter to the constructor, as it implements a
set accessor. This is true for any property, including those inherited from the base
As such, a valid constructor would look like this:
Example of a valid object
The entire class, in its valid form, would look like this:
Example of an invalid object
If the constructor does not contain input parameters for all of the properties which implement only the
get accessor, this will flag as a failure under this check. The following object is therefore incompliant, as only
MyInt has a matching input parameter:
More information on the use of
IImmutable interface within the BHoM can be found here.