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

1 vue (au cours des 30 derniers jours)
Florian Osterloh
Florian Osterloh le 2 Mar 2020
Commenté : Thomas Ewald le 12 Déc 2023
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 commentaires
TADA
TADA le 27 Déc 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 le 12 Déc 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Class Introspection and Metadata dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by