如何在 Visual Studio IDE C# 中隐藏跟踪代码?

发布于 2024-08-26 20:35:35 字数 286 浏览 4 评论 0原文

当我开始在代码中添加更多跟踪时,我意识到它增加了很多混乱。我知道 Visual Studio 允许您隐藏和显示代码,但是,我希望能够将代码分组为“跟踪”代码,然后在阅读代码时随意隐藏和显示。我想它可以为每个文件、每个类或每个函数执行此操作。

有什么办法可以做到这一点吗?你们是做什么的?

添加一些说明

隐藏当前功能允许您执行此操作,只不过当代码隐藏时,您无法判断其是否正在跟踪。您也不能说“隐藏所有跟踪代码”和“显示所有跟踪代码”,这在根据您想要执行的操作读取函数时很有用。

As I'm starting to put more tracing in my code, i'm realizing it adds a lot of clutter. I know Visual Studio allows you to hide and reveal code, however, i'd like to be able group code into "tracing" code and then hide it and reveal at will as i'm reading the code. I suppose it could do this either per file or per class or per function.

Is there any way to do this? What do you guys do?

Adding some clarification

The hide current feature kind of allows you to do this except that when the code is hidden, you can't tell if its tracing or not. You also can't say "hide all tracing code" and "reveal all tracing code" which is useful when reading a function depending on what you are trying to do.

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

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

发布评论

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

评论(2

请你别敷衍 2024-09-02 20:35:35

您考虑过#region吗?

    int x = 3;
    x++;

#region Trace
    // ...
#endregion

    x += 2;

VS会自动让你扩展或隐藏该区域。

Have you considered #region?

    int x = 3;
    x++;

#region Trace
    // ...
#endregion

    x += 2;

VS will automatically allow you to expand or hide the region.

淡水深流 2024-09-02 20:35:35

我建议不要隐藏它。如果样板代码已经到了需要隐藏的阶段,以便您可以看到“真实”代码,那么最好找到一种更好的方法来分离关注点。

这对于跟踪/调试代码来说通常是正确的。我最近看到的是使用 AOP 框架将调试语句注入到其他类中。看看 PostSharpPostSharp。 Sharpcrafters.com/postsharp/documentation/getting-started" rel="nofollow noreferrer" title="example">示例 演示了如何做到这一点。

I'd advise against hiding it. If there's boilerplate code that's getting to the stage where it needs to be hidden away so that you can see the "real" code, then it's better to find a better way to seperate the concerns.

This is often true of tracing/debug code. Something I've looked at recently was to use a AOP framework to inject debug statements into other classes. Have a look at PostSharp, The example demonstrates how to do exactly that.

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