MATLAB: open a restricted property class

MATLAB R2016a introduced a documented mechanism for restricting the class of properties of an object (I know that there is also an older, different, undocumented way to do this, but I do not use this method). For instance:

classdef MyClass
    properties
        myProperty RestrictedClass
    end
end

will restrict the property myPropertyso that its values ​​must be of class RestrictedClass.

If you have implemented such a class, is there a way to use the MATLAB class metadata interface to programmatically discover a class of restricted property?

I was hoping that if I used

m = ?MyClass;
p = m.PropertyList(1);

then the metaproperty object pwill contain information about the class to which it was limited, but it does not seem to be so.

? - , , .

PS , . , , pcode.

+6
1

. meta.Property meta.Validation, :

  Validation with properties:

                 Class: [1Γ—1 meta.class]
                  Size: [1Γ—0 meta.ArrayDimension]
    ValidatorFunctions: {1Γ—0 cell}

:

classdef SOcode
    properties
        myProperty1 double
        myProperty2 struct
    end
end

meta.PropertyList, :

>> test = struct(codemeta.PropertyList(1))

test = 

  struct with fields:

                    Name: 'myProperty1'

                    ... snip ...

                    Type: [1Γ—1 meta.type]
              Validation: [1Γ—1 meta.Validation]
           DefiningClass: [1Γ—1 meta.class]

                    ... snip ...

- :

codemeta = ?SOcode;

nprops = numel(codemeta.PropertyList);
validationclass = cell(nprops, 1);

for ii = 1:nprops
    validationclass{ii} = codemeta.PropertyList(ii).Validation.Class.Name;
end

:

>> validationclass

validationclass =

  2Γ—1 cell array

    {'double'}
    {'struct'}
+2

Source: https://habr.com/ru/post/1015622/


All Articles