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

조회 수: 2 (최근 30일)
Florian Osterloh
Florian Osterloh 2020년 3월 2일
댓글: Thomas Ewald 2023년 12월 12일
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