metaclass

需求

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

方法

利用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.Name

ans =

qubit

>> data.PropertyList

ans = 

  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]
发布了47 篇原创文章 · 获赞 33 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/kaever/article/details/77939290