Class Metadata - MATLAB & Simulink (original) (raw)
Main Content
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 thematlab.metadata.Class
object. For example, create thematlab.metadata.Class
object for thematlab.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 amatlab.metadata.Property
associated with it. Attributes defined for class components correspond to properties in the respective metaclass object.
- matlab.metadata.Namespace — Access from
matlab.metadata.Class
Namespace
property. - matlab.metadata.Class — Create from class name or class object using metaclass function or
?
operator. - matlab.metadata.Property — Access from
matlab.metadata.Class
PropertyList
property. - matlab.metadata.DynamicProperty — Obtain from the addprop method.
- matlab.metadata.Method — Access from
matlab.metadata.Class
MethodList
property. - matlab.metadata.Event — Access from
matlab.metadata.Class
EventList
property. - matlab.metadata.EnumerationMember — Access from
matlab.metadata.Class
EnumerationMemberListList
property.
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 amatlab.metadata.Class
object for the named class. Usematlab.metadata.Class.fromName
with class names stored as characters in variables.matlab.metadata.Class.fromName('_`ClassName`_')
— returns thematlab.metadata.Class
object for the named class (matlab.metadata.Class.fromName is amatlab.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:
Create matlab.metadata.Class
object from class name using thefromName
method:
mc = matlab.metadata.Class.fromName('MyClass');
Create matlab.metadata.Class
object from class instance
obj = MyClass; mc = metaclass(obj);
The metaclass
function returns thematlab.metadata.Class
object (that is, an object of thematlab.metadata.Class
class). You can obtain other metaclass objects (matlab.metadata.Property
,matlab.metadata.Method
, and so on) from thematlab.metadata.Class
object.
Note
Metaclass is a term used here to refer to all the classes in thematlab.metadata
namespace.matlab.metadata.Class
is a class in thematlab.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.