Union

class props.Union

Prop that may be one of several different types of props

This is a type of props.Prop that can be used when a props.HasProps class needs a property that can be multiple types. When the property is assigned, PROPS.UNION attempts to validate it as each type until it succeeds.

Attributes (in addition to those inherited from props.Prop):

PropTypes:
A nested cell array of structs that define the valid prop types. The structs in PropTypes require Type handle but do not require Name or Doc - those are inherited from the PROPS.UNION values. Note: The requirement for nesting the cell array is necessary to subvert MATLAB’s default treatment of cell arrays contained in structs. See the example below for how this is implemented.

Example:

...
class HasUnionProp < props.HasProps
    properties (Hidden, SetAccess = immutable)
        UnionPropStruct = {                                     ...
            struct(                                             ...
                'Name', 'StringOrInt',                          ...
                'Type', @props.Union,                           ...
                'Doc', 'This property is a string or an int>0', ...
                'PropTypes', {{struct(                          ...
                    'Type', @props.Int,                         ...
                    'MinValue', 0                               ...
                ), struct(                                      ...
                    'Type', @props.String                       ...
                )}}                                             ...
            )                                                   ...
        }
    end
    ...
end

See also props.Prop, props.HasProps, props.Int, props.String, props.Repeated, props.Instance