Custom class property and method attributes
5 次查看(过去 30 天)
显示 更早的评论
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!