1
A
回答
2
metaclass
返回meta.class
对象,其中包含有关被查询的类信息。此meta.class
对象的实用属性是PropertyList
,其中包含有关该类的所有属性(包括DefiningClass
)的信息。
使用下面的类定义为例:
classdef asuperclass
properties
thesuperproperty
end
end
和
classdef aclass < asuperclass
properties
theclassproperty
end
end
现在,我们可以查询的aclass
的属性,以确定他们来自何处:
tmp = ?aclass;
fprintf('Class Properties: %s, %s\n', tmp.PropertyList.Name)
fprintf('''theclassproperty'' defined by: %s\n', tmp.PropertyList(1).DefiningClass.Name)
fprintf('''thesuperproperty'' defined by: %s\n', tmp.PropertyList(2).DefiningClass.Name)
其中返回:
Class Properties: theclassproperty, thesuperproperty
'theclassproperty' defined by: aclass
'thesuperproperty' defined by: asuperclass
你可以把它包装成一个简单的帮助函数。例如:
function classStr = definedby(obj, queryproperty)
tmp = metaclass(obj);
idx = find(ismember({tmp.PropertyList.Name}, queryproperty), 1); % Only find first match
% Simple error check
if idx
classStr = tmp.PropertyList(idx).DefiningClass.Name;
else
error('Property ''%s'' is not a valid property of %s', queryproperty, tmp.Name)
end
end
相关问题
- 1. 继承的属性检查
- 2. 在C#中继承的方法属性?
- 3. 搜索由继承者使用的继承类的方法/属性
- 4. 抽象类继承另一个类的方法和属性
- 5. 类图 - 属性继承
- 6. 继承类属性(python)
- 7. Python类 - 属性继承
- 8. Python类属性继承
- 9. Python - 继承类方法来操作类属性
- 10. 继承属性
- 11. 更改继承属性的类型(到继承类型)
- 12. C#中虚拟基类方法/成员的属性继承
- 13. Zend文档:如何查看继承的方法和属性
- 14. 在matlab中查找直方图属性
- 15. Rails - Citier - 两级继承,子类不继承中间类属性
- 16. 查看继承的元素的继承CSS属性
- 17. 从基类继承Grails域类属性
- 18. C#继承父类的属性
- 19. ES6中的属性继承JS类
- 20. 如何获取属性的继承类
- 21. Ruby类中的可继承属性
- 22. CSS继承不父类的属性
- 23. getStaticProperties返回继承的类属性
- 24. 继承的类不具有属性?
- 25. 基类和继承的静态属性
- 26. 继承css属性
- 27. 为继承属性
- 28. 继承CSS属性
- 29. JPQL:访问继承属性的查询
- 30. 使用ActiveRecord在派生类中查找方法 - 单表继承