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

2 次查看(过去 30 天)
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 个评论
TADA
TADA 2021-12-27
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 2023-12-12
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

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Properties 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by