Metadata Interface to Property Validation
For information on property validation, see “Validate Property Values” on page 8-24.
You can determine what validation applies to a property by accessing the validation
metadata. Instances of the meta.Validation class provide the following information
about property validation.
- Class requirement of the property specified as a meta.class object
- Size requirements of the property value specified as an array of
meta.FixedDimension and meta.UnrestrictedDimension objects - Function handles referencing validation functions applied to property values specified
as a cell array of function handles.
For example, the ValidationExample class defines a property that must be an array of
doubles that is 1-by-any number of elements and must be a real number that is greater
than 10.
classdef ValidationExample
properties
Prop (1,:) double {mustBeReal, mustBeGreaterThan(Prop, 10)} = 200;
end
end
Access the meta.Validation object from the property's meta.property object. Get
the validation information from the meta.Validation object properties. Collection this
information into a cell array.
- Get the size information from the Size property
- Get the class name from the Class property
- Get a cell array of function handles for the validation functions from the
ValidatorFunctions property.
mc = ?ValidationExample;
mp = findobj(mc.PropertyList,'Name','Prop');
sz = mp.Validation.Size;
len = length(sz);
dim = cell(1:len);
for k = 1:len
switch class(sz(k))
case 'meta.FixedDimension'
8 Properties — Storing Class Data