switch evt.PropertyName
case 'SpecialProp'
% Take action based on the addition of this property
%...
%...
src.HiddenProp = true;
disp('SpecialProp added')
otherwise
% Other property added
% ...
disp([evt.PropertyName,' added'])
end
case 'PropertyRemoved'
switch evt.PropertyName
case 'SpecialProp'
% Take action based on the removal of this property
%...
%...
src.HiddenProp = false;
disp('SpecialProp removed')
otherwise
% Other property removed
% ...
disp([evt.PropertyName,' removed'])
end
end
end
Create an object of the DynamTest class.
dt = DynamTest;
Add a listener for both PropertyAdded and PropertyRemoved events.
lad = addlistener(dt,'PropertyAdded',@DyPropEvtCb);
lrm = addlistener(dt,'PropertyRemoved',@DyPropEvtCb);
PropertyAdded Event Callback Execution
Adding a dynamic property triggers the PropertyAdded event. This statement adds a
dynamic property to the object and saves the returned meta.DynamicProperty object.
ad = addprop(dt,'SpecialProp');
Dynamic Property Events