Custom class property and method attributes
5 ビュー (過去 30 日間)
古いコメントを表示
Thomas Satterly
2019 年 9 月 10 日
コメント済み: Thomas Satterly
2019 年 11 月 4 日
I'd like to be able to define my own attributes in classes, but I'm not finding any documentation as to how that might be done. My main goal is to be able to create a property attribute, "UseAsReference", that marks object properties that need to be saved and loaded via custom methods because they are references to other Matlab handle objects. I'm hoping to accomplish this with property attributes and a superclass rather than defining an interface so that I don't have to worry about maintaining a constant list of reference properties and custom save/load functions for each implementing member. The pages for property and method attributes note that inheriting from certian frameworks (e.g., the UnitTest framework) will open up more attributes that a class can use. Is it possible to replicate this functionality?
2 件のコメント
Adam
2019 年 11 月 4 日
I'm not entirely sure what it is you are wanting, and didn't notice the question at the time, though as you seem to have found an answer now I guess it doesn't matter. I'd have thought dependent properties could have been utilised to achieve this though.
I did implement my own class called a JustInTimeProperty to store certain data in my classes too as I have cases where I want the property to only be calculated when first asked for, but then stored thereafter, rather than a pure dependent property which would always recalculate or a regular property which would have to be calculated upfront even if it is never actually asked for.
I can't remember the exact implementation i had for these and it isn't the same scenario you want anyway, but their usage did make use of dependent properties, paired with private properties.
採用された回答
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!