Main Content

Class Metadata

What Is Class Metadata?

Class metadata is information about class definitions that is available from various metaclasses objects. Use metaclass objects to obtain information without having to create instances of the class. Metadata enables the programmatic inspection of classes. Each metaclass has properties, methods, and events that contain information about the class or class component it describes.

All class components have an associated metaclass, which you access from the matlab.metadata.Class object. For example, create the matlab.metadata.Class object for the matlab.alias.AliasFileManager class:

mc = ?matlab.alias.AliasFileManager
mc = 

  Class with properties:

                     Name: 'matlab.alias.AliasFileManager'
              Description: 'Create and edit alias definition files'
      DetailedDescription: '  Use an AliasFileManager object to create...'
                   Sealed: 1
                 Abstract: 0
              Enumeration: 0
          ConstructOnLoad: 0
         HandleCompatible: 1
          InferiorClasses: [0×1 matlab.metadata.Class]
                Namespace: [1×1 matlab.metadata.Namespace]
                  Aliases: [0×1 string]
     RestrictsSubclassing: 1
             PropertyList: [1×1 matlab.metadata.Property]
               MethodList: [28×1 matlab.metadata.Method]
                EventList: [1×1 matlab.metadata.Event]
    EnumerationMemberList: [0×1 matlab.metadata.EnumerationMember]
           SuperclassList: [1×1 matlab.metadata.Class]

The matlab.metadata Namespace

The matlab.metadata namespace contains metaclasses that describe the definition of classes and class components. The class name indicates the component described by the metaclass. For example, each class property has a matlab.metadata.Property associated with it. Attributes defined for class components correspond to properties in the respective metaclass object.

Metaclass Objects

You cannot instantiate metaclasses directly by calling the respective class constructor. Create metaclass objects from class instances or from the class name.

  • ?ClassName — Returns a matlab.metadata.Class object for the named class. Use matlab.metadata.Class.fromName with class names stored as characters in variables.

  • matlab.metadata.Class.fromName('ClassName') — returns the matlab.metadata.Class object for the named class (matlab.metadata.Class.fromName is a matlab.metadata.Class method).

  • metaclass(obj) — Returns a metaclass object for the class instance (metaclass)

Create matlab.metadata.Class object from class name using the ? operator:

mc = ?MyClass;

Create matlab.metadata.Class object from class name using the fromName method:

mc = matlab.metadata.Class.fromName('MyClass');

Create matlab.metadata.Class object from class instance

obj = MyClass;
mc = metaclass(obj);

The metaclass function returns the matlab.metadata.Class object (that is, an object of the matlab.metadata.Class class). You can obtain other metaclass objects (matlab.metadata.Property, matlab.metadata.Method, and so on) from the matlab.metadata.Class object.

Note

Metaclass is a term used here to refer to all the classes in the matlab.metadata namespace. matlab.metadata.Class is a class in the matlab.metadata namespace whose instances contain information about MATLAB® classes. Metadata is information about classes contained in metaclasses.

Metaclass Object Lifecycle

When you change a class definition, MATLAB reloads the class definition. If instances of the class exist, MATLAB updates those objects according to the new definition.

However, MATLAB does not update existing metaclass objects to the new class definition. If you change a class definition while metaclass objects of that class exist, MATLAB deletes the metaclass objects and their handles become invalid. You must create a new metaclass object after updating the class.

For information on how to modify and reload classes, see Automatic Updates for Modified Classes.

Related Topics