Can I get information of used method arguments validation by meta.class

3 visualizzazioni (ultimi 30 giorni)
Hello,
I would like to collect information about used validation in arguments block of class methods.
Currently I get information about property validation through meta.class,
mco = ?memmapfile;
findobj(mco, 'Name','Filename' )
ans =
property with properties:
Name: 'Filename'
Description: ''
DetailedDescription: ''
GetAccess: 'public'
SetAccess: 'public'
Dependent: 1
Constant: 0
Abstract: 0
Transient: 0
Hidden: 0
GetObservable: 0
SetObservable: 0
AbortSet: 0
NonCopyable: 1
GetMethod: @C:\Program Files\MATLAB\R2019b\toolbox\matlab\iofun\@memmapfile\memmapfile.m>memmapfile.get.Filename
SetMethod: @C:\Program Files\MATLAB\R2019b\toolbox\matlab\iofun\@memmapfile\memmapfile.m>memmapfile.set.Filename
HasDefault: 0
Validation: [0x0 meta.Validation]
DefiningClass: [1x1 meta.class]
Here I take the meta.Validation. For example in my custom class:
>> findobj(?MyRectangle, 'Name','length' ).Validation
ans =
Validation with properties:
Class: [1x1 meta.class]
Size: [1x0 meta.ArrayDimension]
ValidatorFunctions: {@mustBeNumeric}
Can I get this information for argument validation in class methods as well? By meta.class ? Does anybody know how to do it?
  3 Commenti
TADA
TADA il 27 Dic 2021
to make things worse, when I add the arguments block, metaclass no longer identifies the argumets list at all:
classdef Class
methods
function z = foo(obj, x, y)
z = x*y;
end
end
end
mc = ?Class;
mf = mc.MethodList(strcmp({mc.MethodList.Name}, 'foo'));
mf.InputNames
ans =
3×1 cell array
{'obj'}
{'x' }
{'y' }
When I add the arguments validatin block:
classdef Class
methods
function z = foo(obj, x, y)
arguments
obj
x {mustBeNumeric(x)}
y {mustBeNumeric(y)}
end
z = x*y;
end
end
end
mc = ?Class;
mf = mc.MethodList(strcmp({mc.MethodList.Name}, 'foo'));
mf.InputNames
ans =
1×1 cell array
{'varargin'}
Thomas Ewald
Thomas Ewald il 12 Dic 2023
Hello!
I am currently dealing with the same problem. Adding an argument validation results in the InputNames property returning only 'varargin'. Has some solution been found yet?
All the best! TE

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Class Introspection and Metadata in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by