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
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
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 Center 和 File Exchange 中查找有关 Properties 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!