metaclass

来源:互联网 发布:菜鸟网络的现状 编辑:程序博客网 时间:2024/05/20 13:36

需求

有时我们需要知道一个类有哪些属性和方法。已知条件:该类的一个对象。

方法

利用metaclass()。metaclass(object)返回meta.class对象,这个类对象包含所有的object类的信息。

code

>> data=metaclass(C)data =   class (具有属性):                     Name: 'qubit'              Description: ''      DetailedDescription: ''                   Hidden: 0                   Sealed: 0                 Abstract: 0              Enumeration: 0          ConstructOnLoad: 0         HandleCompatible: 0          InferiorClasses: {0×1 cell}        ContainingPackage: [0×0 meta.package]             PropertyList: [1×1 meta.property]               MethodList: [2×1 meta.method]                EventList: [0×1 meta.event]    EnumerationMemberList: [0×1 meta.EnumeratedValue]           SuperclassList: [0×1 meta.class]>> data.Nameans =qubit>> data.PropertyListans =   property (具有属性):                   Name: 'type'            Description: ''    DetailedDescription: ''              GetAccess: 'public'              SetAccess: 'public'              Dependent: 0               Constant: 0               Abstract: 0              Transient: 0                 Hidden: 0          GetObservable: 0          SetObservable: 0               AbortSet: 0            NonCopyable: 0              GetMethod: []              SetMethod: []             HasDefault: 0          DefiningClass: [1×1 meta.class]
原创粉丝点击