meta.class.fromName

Returns the meta.class object that describes a class, given its name.

Category: Programming > Classes

Syntax

mc = meta.class.fromName('ClassName')

Returns a description of the class named ClassName.

Description

Metaclass objects let a program inspect classes without having an instance: the properties, methods and events they declare, and the superclasses. The shorthand ?ClassName returns the same object in MATLAB.

For a name that is not a class on the path the result is empty, so test it with isempty before reading its properties.

Input arguments

'ClassName'
Name of a class, as text.

Output arguments

mc
A meta.class object. Its Name, PropertyList, MethodList and EventList describe the class.

Example

A name that is not a class

mc = meta.class.fromName('NoSuchClass');
isempty(mc)
Output
ans = logical
   1

See also

ismethod isprop events enumeration