您可以使用将对象转换为结构的未记录的hack来检查对象的非公共属性. 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'}