在 Visual Studio 中隐藏区域
我知道 VS 代码折叠问题是一个老问题,但我在浏览过的所有其他讨论中都找不到这一点:
我们有一个 C# 团队,一些人喜欢区域,另一些人讨厌他们,但我们不这样做。似乎没有太多中间立场可以合作。
VS 是否有一个插件或加载项可以“隐藏”区域? 这样那些想要它们的人就会像平常一样看到它们,但安装加载项并查看 .cs 文件的人却看不到这些区域,就好像它们不存在一样。
我可以看到,在移动代码时这可能是一个问题,它可能会导致某些方法在错误区域之内或之外出现问题,但这可能是团队满意的权衡...
I know VS code folding issues are an old chestnut, but I haven't been able to find this in all the other discussions I have browsed through:
We have a team of C# guys, some love regions and others hate them and we don't seem to have much middle ground to work with.
Is there a plug- or add-in for VS that will just 'hide' the regions? So that those that want them will see them as normal, but the people that install the add-in and view a .cs file the regions just aren't there, as if they don't exist.
I can see this might be an issue when moving code around that it might cause issues of certain methods being in or outside of the wrong region, but that might be a tradeoff the team is happy with...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我讨厌区域(我的团队喜欢它们),并且惊讶地发现没有人编写扩展来使它们变得更好。 我终于自己写了一个名为我讨厌#Regions:
让#regions 少一些烂(免费):
http://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca
I hate regions (my team loves them) and was surprised to find that nobody has written an extension to make them better. I finally wrote one myself called I Hate #Regions:
Make #regions suck less (for free):
http://visualstudiogallery.msdn.microsoft.com/0ca60d35-1e02-43b7-bf59-ac7deb9afbca
有快捷键可以处理它们:
请参阅代码折叠的问题
There are shortcut keys to deal with them:
See The Problem With Code Folding
就我个人而言,我编写了一个 VS 宏(“工具”>“宏”)来扩展打开文件时的所有区域。
Personally, I write a VS macro (Tools > Macro) to expand all regions on file open.
老实说,我不知道有这样的插件。 但是,使用 VSTO,您自己编写一个非常容易。
I don't know of any plugin like that, honestly. However, with VSTO, it's very easy to write one yourself.
这有点......肮脏,并且可能有副作用,但是:
工具-->选项-->环境-->字体和颜色-->预处理器关键字
将前景色和背景色更改为白色(或任何默认背景)。
不过,您不会看到其他预处理器关键字。
This is somewhat... sleazy, and may have side-effects but:
Tools-->Options-->Environment-->Fonts and Colors-->Preprocessor Keyword
Change the foreground and background colours to white (or whatever your default background is).
You wont see other preprocessor keywords though.
对于 VS 2008 用户,您可以停止大纲并以编程方式重新启动(通过宏)。 我在 http://weblogs.asp.net/ 找到了这段代码rweigelt/archive/2003/07/06/9741.aspx
以上适用于 C# IDE; 由于某些原因,VB 的 IDE 在明确告知时不会删除区域轮廓。 希望这可以帮助!
-- 附加编辑:
这里有一个适用于 Visual Studio 2008 中的 Visual Basic .NET 的方法。这有点暴力,但其想法是注释所有 #region 标记,扩展轮廓。 下一步取消注释它们,将它们返回到原始状态(严格来说并不正确......可能在代码的其他部分中恶意使用#region)。 此代码不返回 Find & 将对话框替换回其原始状态。 有了这些注意事项,这是将执行此杂务的宏模块:
在 VS2008 中可能有一些其他方法可以为 VB 完成此操作。 当我找到它们时我会发布。
For VS 2008 users, you can stop outlining and restart it programatically (via a macro). I found this code at http://weblogs.asp.net/rweigelt/archive/2003/07/06/9741.aspx
The above works for C# IDE; for some reason, VB's IDE doesn't remove outlining with regions when explicitly told to. Hope this helps!
-- appended edit:
Here's one that does work for Visual Basic .NET in Visual Studio 2008. It's a bit of brute force, but the idea is to comment all of the #region markers, expanding the outline. The next step uncomments them, returning them to their original state (not strictly true... could have rogue uses of #region in other parts of the code). This code doesn't return the Find & Replace dialog back to it's original state, either. With those caveats, this is the macro module that will perform this chore:
There may be a few other methods to accomplish this for VB in VS2008. I'll post as I find them.
我认为讨厌地区的人很有趣。 我非常喜欢 Regions,因此编写了一个名为 Regionizer 的程序,这是一个开源项目,位于 http://regionizer.codeplex.com
我的老板和一些团队成员讨厌他们,但我的工具按字母顺序组织所有代码,因此方法在方法区域中按字母顺序排序,属性在属性区域中排序,事件在事件区域中排序。
尝试在没有此工具(或区域)的情况下查找代码就是我所说的意大利面条代码)。
我一直在寻找一种简单的方法来折叠和展开所有区域,并被 MS 告知这些区域是 .suo 文件的一部分(与项目或解决方案同名),并且没有一种简单的方法来获取句柄各地区反对他们自己。
我已经搜索了整个 DTE,但没有找到折叠所有或展开所有区域的方法,我将尝试宏代码,看看它是否有效。
很快就会发布更新。
I think it is funny anyone that hates Regions. I love Regions so much I wrote a program called Regionizer, which is an open source project located at http://regionizer.codeplex.com
I have had bosses and some team members who hate them, but my tool organizes all code alphabetically, so methods are alphabetically sorted in the Methods Region, Properties are sorted in the Properties Region, and Events are sorted in the Events region.
Try to find code without this tool (or Regions) is what I call Spaghetti Code).
I have been searching for an easy way to collapse and expand all regions and have been told by MS that the regions are part of the .suo file (same name as the project or solution) and there is not an easy way to get a handle on the regions object them selves.
I have searched all through the DTE and I haven't found a way to collapse all or Expand all regions, I am going to try the Macro code and see if it works.
Will post an update shortly.