MATLAB Answers

Using dynamic references to dynamic properties within those property's common set/get method.

4 views (last 30 days)
Curtis on 5 Jan 2017
Commented: Curtis on 5 Jan 2017
I have a class which is a subclass of dynamicprops.
I specify a common get method for each dynamic property by using an anonymous function that references a set method but also provides the name of the property. Similar to the following:
metaprop = obj.addprop(name); metaprop.GetMethod = @(obj) getProp(obj,name);
getProp is defined as the folowing method of the class:
function val = getProp(obj,propertyName) val = obj.(propertyName); end
This ends up throwing an error, "Maximum recursion limit of 501 reached." It seems that even though I am accessing that function from within the get property function, it is still calling the get method. Must be because the actual get method is the anonymous function so it doesn't recognize the getProp as the get method and so calls the anonymous function again for obj.(propertyName) Any better ideas to fix this?

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!