检查和编辑对象的私有/受保护属性

发布于 2024-12-11 11:35:06 字数 233 浏览 0 评论 0原文

在 MATLAB 2011b 中,我有一些类具有许多私有或受保护的类属性。这是设计使然,因为我不希望这些除了我的类自己的 getter/setter 之外的任何东西都可以查看、可读、可写等。

然而,在开发过程中有时我想看看这些属性的状态。类对象可在工作区中检查,但是当我通过双击工作区中的对象访问变量编辑器工具时,所有私有/受保护的属性都不可见。

我可以理解这可能是设计使然,但我希望有一个我缺少的设置可以让我查看它们。

In MATLAB 2011b, I have some classes that have a number of private or protected class properties. This is by design, as I do not want these to be viewable, readable, writable, etc. by anything other than my class's own getters/setters.

However, there are times during development when I want to see what the state of these properties are. The class object is available to inspect in the workspace, but when I access the Variable Editor tool by double-clicking the object in the Workspace, none of the private/protected properties are visible.

I can understand that this is probably by design, but I'm hoping there is a setting I'm missing that will let me view them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暖心男生 2024-12-18 11:35:06

如果您不想修改属性以进行调试,则可以使用调试器来检查私有/受保护的变量。为了方便起见,您甚至可以编写一个进入调试器的方法,这样您就不必手动设置停止:

classdef testObj_debug
    properties (Access=private)
        p1 = 4;
    end

    methods (Hidden)
        function checkProps(obj)
            keyboard
        end
    end
end

如果您调用 to = testObj_debug, to.checkProps,您正在访问调试模式,其中隐藏属性 p1 是可访问和检查的。

If you don't want to modify the attributes for debugging, then you can instead use the debugger to inspect the private/protected variables. For convenience, you can even write a method that gets you into the debugger, so that you don't have to manually set a stop:

classdef testObj_debug
    properties (Access=private)
        p1 = 4;
    end

    methods (Hidden)
        function checkProps(obj)
            keyboard
        end
    end
end

If you call to = testObj_debug, to.checkProps, you are accessing the debug mode, in which the hidden property p1 is accessible and inspectable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文