How can function argument declaration be introspected?

30 次查看(过去 30 天)
Is there a way to programmatically access the function argument validation declared in the argument block? meta.method introspection only allows to determine argument names, but I am interested in all of the validation features (dimensions, class, validation functions).
My need especially focuses on functions (not only class methods) and also on output arguments.
  3 个评论
Sean
Sean 2024-8-8,20:49
This is an old question with no answers. So I assume there was no way to do this back in 2022. Has there been any changes? I am also very interested in doing this.
Umar
Umar 2024-8-8,22:00
编辑:Walter Roberson 2024-8-8,22:25
Hi @Simon Sigl,
As I am aware of argument validation enhances code readability and maintainability by enforcing specific input and output requirements. However, traditional introspection methods, such as `meta.method`, only reveal argument names without detailing the associated validation criteria (e.g., size, class). I doubt that if there is no built-in method for programmatically accessing full argument validation details declared in the `arguments` block. Also, the`meta.method` class provides some metadata but does not extend to validation features. I would suggest implementing a mechanism within your functions to document validations explicitly using structured data.Use documentation comments to describe validations, enhancing code readability. Explore `meta.class` along with `meta.method` for structured understanding of class methods. Please bear in mind that Output arguments can also be validated, but similar strategies apply for introspection.
Here are some useful links that will help your aid in your research.
In nutshell, while direct programmatic access to detailed argument validations in MATLAB is currently limited, utilizing custom structures and thorough documentation can effectively address these challenges. Future updates may further improve these capabilities.

请先登录,再进行评论。

回答(0 个)

类别

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

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by