Custom class properties and method attributes

20 Ansichten (letzte 30 Tage)
Jan Kappen
Jan Kappen am 26 Okt. 2021
Is there a way to add custom property or method attributes to handle classes? It is done by several classes or toolboxes, e.g. the unit testing framework allows to add tags to the methods: Tag Unit Tests - MATLAB & Simulink (mathworks.com)
classdef ExampleTagTest < matlab.unittest.TestCase
methods (Test)
function testA (testCase)
% test code
end
end
methods (Test, TestTags = {'Unit'})
function testB (testCase)
% test code
end
function testC (testCase)
% test code
end
end
I'm talking about the attributes "Test" and "TestTags".
My application would greatly benetfit from a finer granular control of properties for a DTO (data transfer object) class. I want to use argument validation but add additional options like overridable properties and don't want to use inputParser anymore :)
Thanks!
  6 Kommentare
Jim Svensson
Jim Svensson am 22 Mär. 2023
As far as I know Matlab does not (version<=R2023) support custom property attributes. But if you are not using some of the existing ones for anything you might use them. For example SetObservable or GetObservable can be used to mean something else if you are not using listeners.
Jan Kappen
Jan Kappen am 22 Mär. 2023
Thanks for that recommendation but I'm quite reluctant to abuse existing attributes that have a pretty clear meaning :)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 26 Okt. 2021
I don't know why it's not documented, but apparently there is a Description attribute that can be added, e.g.,
classdef myclass
properties (Description='propTag')
prop
end
methods (Description='methTag')
function meth1
end
end
methods
function meth2
end
end
end
  3 Kommentare
Matt J
Matt J am 26 Okt. 2021
Bearbeitet: Matt J am 26 Okt. 2021
Would you expect that Description field to be existent in the next releases?
Since it's not documented, it's hard to know for certain. Hopefully, someone from the MathWorks will weigh in.
Does this address your question, though? If so, I'd be much obliged if you would Accept-click the answer.
Ill-Conditioned Matrix
Ill-Conditioned Matrix am 8 Jun. 2023
The problem is that Description and DetailedDescription come from the comment block before the property declaration. If you set Description from the property declaration, it will override the comments, but I'm not sure whether we can rely on that behavior.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Argument Definitions finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by