meta.property class
Package: meta
Superclasses: meta.MetaData
Describe property of MATLAB class
Description
The meta.property
class provides information about the properties of MATLAB® classes. Properties of the meta.property
class contain the values of property attributes and other information that is specified syntactically in the class definition. All properties are read-only.
The meta.property
class is a handle
class.
Class Attributes
Abstract | true |
ConstructOnLoad | true |
For information on class attributes, see Class Attributes.
Creation
You cannot instantiate a meta.property
object directly. Obtain a meta.property
object from the meta.class
PropertyList
property, which contains an array of meta.property
objects, one for each class property. For example, replace ClassName
with the name of the class whose properties you want to query:
mco = ?ClassName;
plist = mco.PropertyList;
mp = plist(1); % meta.property for first property in list
Use the metaclass
function to obtain a meta.class
object from a class instance:
mco = metaclass(obj);
Properties
Name
— Property name
character vector
Property name, returned as a character vector. The meta.property
Name
property corresponds to the name of the associated property defined by the class.
Description
— Short description of property
character vector
Short description of the property, returned as a character vector. For user-defined classes, the text for this property comes from code comments for the property definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class properties, see Custom Help Text.
DetailedDescription
— Detailed description of property
character vector
Detailed description of the property, specified as a character vector. For user-defined classes, the text for this property comes from code comments for the property definition. If there are no comments, the property returns an empty character vector. For more information on how to include help text for your class properties, see Custom Help Text.
GetAccess
— Read access level of property
public
(default) | protected
| private
| one or more meta.class
objects
The read (get) access level of the property, returned as:
public
— unrestricted accessprotected
— access from class or subclassesprivate
— access by class members only (not from subclasses)List of classes that have read access to this property, specified as
meta.class
objects in the form:A single
meta.class
object.A cell array of
meta.class
objects. An empty cell array,{}
, is the same asprivate
access.
For more information, see Class Members Access.
Data Types: enumerated
| meta.class
SetAccess
— Write access level of property
public
(default) | protected
| private
| one or more meta.class
objects
The write (set) access level of the property, returned as:
public
— unrestricted accessprotected
— access from class or subclassesprivate
— access by class members only (not from subclasses)immutable
— property can only be set by constructor. For more information, see Mutable and Immutable Properties.List of classes that have write access to this property, specified as
meta.class
objects in the form:A single
meta.class
object.A cell array of
meta.class
objects. An empty cell array,{}
, is the same asprivate
access.
For more information, see Class Members Access.
Data Types: enumerated
| meta.class
Dependent
— Does property value depends on other values
false
(default) | true
Does the property value depend on other values, returned as logical
true
or false
. If false
(the
default), the property value is stored in the object. If true
, the
property value is not stored in the object, and the set and get functions cannot access
the property by indexing into the object using the property name. Dependent properties
must define access methods. For more information, see Get and Set Methods for Dependent Properties.
Constant
— Is property value constant
false
(default) | true
Is the property value constant, returned as logical true
or
false
. If true
, this property has the same value
in all instances of the class. For more information, see Define Class Properties with Constant Values.
Abstract
— Is property abstract
false
(default) | true
Is the property abstract, returned as logical true
or
false
. If true
, the property has no
implementation and the class is abstract. For more information, see Abstract Classes and Class Members.
Transient
— Is property saved with object
false
(default) | true
Is the property saved with the object, returned as logical true
or false
. If true
, the property value is not saved
when the object is saved to a MAT file. For more information about saving objects, see
Save and Load Process for Objects.
Hidden
— Is the property hidden from the property list
false
(default) | true
Is the property hidden from the property list, returned as logical
true
or false
. Hidden
determines if the property is shown in a property list (as a result of a call to
properties
, for example). Hidden properties
are not shown in the default object display.
GetObservable
— Can listeners receive property get events
false
(default) | true
Can listeners receive property get events, returned as logical true
or false
. If true
, and it is a handle class property, then you can create listeners that execute when the property value is queried. MATLAB calls the listeners whenever property values are queried. For more information, see Property-Set and Query Events.
SetObservable
— Can listeners receive property set events
false
(default) | true
Can listeners receive property set events, returned as logical
true
or false
. If true
, and
it is a handle class property, then you can create listeners that execute when the
property value is set. MATLAB calls the listeners whenever property values are modified. For more
information, see Property-Set and Query Events.
AbortSet
— Is property set if value is unchanged
false
(default) | true
Is property set if value is unchanged, returned as logical true
or false
. If true
, then setting a property value is aborted if the new value is the same as the current value. If the property belongs to a handle class, setting AbortSet
to true
prevents the triggering of property PreSet
and PostSet
events.
NonCopyable
— Is property copyable
false
(default) | true
Is the property copyable, returned as logical true
or
false
. If false
, the property value is copied
when the object is copied (handle
class only). By default, copying a
handle object copies the concrete properties of that object. For more information, see
Exclude Properties from Copy.
PartialMatchPriority
— Priority for partial name matching
1 (default) | positive integer
Priority for partial name matching, returned as a numeric value. Use with subclasses
of matlab.mixin.SetGet
to define the relative
priority of partial property name matches used in set
and
get
method arguments. The default value is 1. Greater values assign
lower priorities. For more information, see Set Priority for Matching Partial Property Names.
GetMethod
— Property get method
[]
(default) | function handle
Property get method, returned as a function handle or an empty value. Function handle of the get method associated with this property. The value is empty if there is no get method specified in the class definition. For more information, see Property Get and Set Methods.
SetMethod
— Property set method
[]
(default) | function handle
Property set method, returned as a function handle or an empty value. Function handle of the set method associated with this property. The value is empty if there is no set method specified in the class definition. For more information, see Property Get and Set Methods
HasDefault
— Does property define a default value
false
(default) | true
Does the property define a default value, returned as logical
true
or false
. If true
, the
property defines a default value in the class definition. Test
HasDefault
before querying the DefaultValue
property to avoid a MATLAB:class:NoDefaultDefined
error.
Data Types: logical
DefaultValue
— Default value specified in class definition
none (default) | array
Default value specified in the class definition. Abstract, dependent, and dynamic properties cannot specify default values.
If there is no default value in the class definition, MATLAB does not display the DefaultValue
property. Test
HasDefault
before querying the DefaultValue
property to avoid a MATLAB:class:NoDefaultDefined
error.
Validation
— Validation defined for property
empty (default) | meta.Validation
object
Validation defined for property, returned as a meta.Validation
object. This property contains a meta.Validation
object describing the validation defined by this property. If the property does not define validation, this property contains an empty meta.Validation
object.
DefiningClass
— Class that defines the property
meta.class
object
Class that defines the property, returned as a meta.class
object. The meta.class
object represents the class that defines this property, which can be a superclass.
Events
Event Name | Trigger | Event Data | Event Attributes |
---|---|---|---|
PreGet | Event occurs just before the property value is queried. | event.PropertyEvent |
|
PostGet | Event occurs just after the property value has been queried. | event.PropertyEvent |
|
PreSet | Event occurs just before the property value is changed. | event.PropertyEvent |
|
PostSet | Event occurs just after the property value has been changed. | event.PropertyEvent |
|
Examples
Use Introspection to Get Information About Property
Use meta.property
to get information about a class property of the IntrospectionExample
class.
Code for IntrospectionExample
classdef IntrospectionExample % IntrospectionExample Performs basic functions on two numbers % This class can return the sum and product of its two properties. properties % a First property % First of two numeric properties a {mustBeNumeric} = 0 % b Second property % Second of two numeric properties b {mustBeNumeric} = 0 end methods function sum = addNumbers(obj) % addNumbers Sum the properties % Finds the sum of properties a and b. sum = obj.a + obj.b; end function prod = multNumbers(obj) % multNumbers Multiply the properties % Finds the product of properties a and b. prod = obj.a*obj.b; end end end
Create and Inspect a Metaclass Instance
Create a metaclass instance for IntrospectionExample
. Access the first property in the PropertyList
of mc
to get a meta.property
object.
mc = ?IntrospectionExample; mc.PropertyList(1)
ans = property with properties: Name: 'a' Description: 'First property' DetailedDescription: ' First of two numeric properties' GetAccess: 'public' SetAccess: 'public' Dependent: 0 Constant: 0 Abstract: 0 Transient: 0 Hidden: 0 GetObservable: 0 SetObservable: 0 AbortSet: 0 NonCopyable: 0 PartialMatchPriority: 1 GetMethod: [] SetMethod: [] HasDefault: 1 DefaultValue: 0 Validation: [1x1 meta.Validation] DefiningClass: [1x1 meta.class]
Check what validation the class performs on the property value.
mc.PropertyList(1).Validation
ans = Validation with properties: Class: [0x0 meta.class] Size: [1x0 meta.ArrayDimension] ValidatorFunctions: {@mustBeNumeric}
Version History
Introduced in R2008aR2022a: Description
and DetailedDescription
properties contain text from code comments
For user-defined classes with appropriately placed code comments, the
Description
and DetailedDescription
properties
are populated with text pulled from those comments. For more information on how to use code
comments to store custom help text for user-defined classes, see Custom Help Text.
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)