Visual Studio 中按字母顺序排列的方法
Visual Studio 2008 是否有任何类型的插件或工具可用于按字母顺序排列方法? 理想情况下,我想要一个能够自动或按需按字母顺序排列选择或指定类型(即只有方法,而不是成员变量)的工具。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
Visual Studio 2008 是否有任何类型的插件或工具可用于按字母顺序排列方法? 理想情况下,我想要一个能够自动或按需按字母顺序排列选择或指定类型(即只有方法,而不是成员变量)的工具。
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
虽然 Resharper 具有许多很酷的功能,但它对 CPU 和 I/O 使用率有很大影响,并且使用起来非常复杂。 它也只能在商业许可下使用,除非您有资格获得一些非常具体的免费使用许可。
尝试 CodeMaid。 它可以免费用于商业用途,并且性能开销要低得多。 我发现它很容易使用,并且对于按字母顺序排列的方法非常有用。
要对文件进行排序,请通过解决方案资源管理器打开文件:
重新组织活动文档
或者,使用默认的 CodeMaid 热键< kbd>CTRL+M,Z 对活动文件进行排序。
While Resharper has many cool features it has a large impact in CPU and I/O usage and can be very complicated to use. It is also only available under commercial licensing unless you qualify for a few very specific free use licenses.
Try CodeMaid. It is free for commercial use and has a much lower performance overhead. I find it easy to use and it is very good for alphabetizing methods.
To sort your file, open the file via solution explorer:
Reorganize Active Document
Alternatively, using the default CodeMaid hotkeys CTRL+M,Z to sort your active file.
Resharper 有一个类型成员布局,它可以按类型、可访问性和字母顺序对成员进行排序。
您还可以查看 Ora ,它在 Visual Studio 中显示了一个按顺序排列的窗格(即使您的来源可能不是)。链接已失效。Resharper has a Type Members Layout, which can order members by type, accessibility and alphabetically as well.
You can also take a look into Ora , which presents a pane in visual studio that is ordered (even though your source may not be).Link's dead.下面的答案比OP的要求更进一步,因为我相信,仅按名称对方法进行排序对于大多数程序员来说是远远不够的。 大多数情况下,您希望方法、构造函数、字段、事件处理程序和接口实现彼此分离(即通过区域),并按各种标准排序。
为此,我尝试了 NArrange、Regionerate 等,但我发现它们使用起来并不直观。 所以ReSharper成为我选择的工具。
正如 @DavidN 已经提到的,ReSharper 可以按名称、可访问性、类型、只读等对类成员(字段、构造函数、方法、委托)进行排序...您还可以用区域包围特定成员。 我最喜欢的是对接口成员(例如,
#region IDisposable
以及其中的void Dispose()
方法)和处理事件的方法进行分组的能力。ReSharper 提供了两种配置和触发类成员排序的简单方法。
配置布局
在 Visual Studio 中创建一个 XML 文件,并将默认类型成员布局(ReSharper 选项 > 语言 > C# > 类型成员布局)复制粘贴到该文件中。 下载最新的 XSD 架构。 将架构文件添加到 Visual Studio 的架构文件中(菜单 > XML > 架构... > 添加)。 您现在应该能够使用 IntelliSense 支持来编辑 XML 文件。
触发重新排序
如果您使用 Visual Studio 键盘方案(ReSharper 选项 > Visual Studio 集成)并按 Ctrl+E、F 用于静默代码清理。 将弹出一个对话框,您可以在其中选择代码清理设置。 对于此设置,您应该选中重新排序类型成员。 第二次按快捷键时,ReSharper 将自动对班级成员重新排序。
1:ReSharper 类型成员 XSD 架构
The following answer goes much further than the OP asks, because I believe, that sorting methods just by name is far not enough for most programmers. Mostly you want your methods, constructors, fields, event handlers, and interface implementations to be seperated from each other (i.e. through regions), and sorted by various criteria.
For this purpose I tried NArrange, Regionerate, and others, but I've found them not intuitive to use. So ReSharper became the tool of my choice.
As already mentioned by @DavidN, ReSharper can sort your class members (fields, constructors, methods, delegates) by name, accessibility, type, readonly, etc... You can also surround specific members with regions. What I like the most is the ability to group interface members (e.g.,
#region IDisposable
withvoid Dispose()
method in it) and methods that handle an event.ReSharper provides both - an easy way to configure and trigger the sorting of class members.
Configuring the layout
Create a XML file within Visual Studio and copy-paste the default type member layout (ReSharper Options > Languages > C# > Type Members Layout) into that file. Download the latest XSD schema. Add the schema file to Visual Studio's schema files (Menu > XML > Schemas... > Add). You should be able now, to edit the XML file with IntelliSense support.
Triggering the reorder
If you use the Visual Studio keyboard scheme (ReSharper Options > Visual Studio Integration) and press Ctrl+E,F for Silent Code Cleanup. A dialog will pop up, where you can select a Code Cleanup setting. For this setting you should check Reorder type members. The second time you press the shortcut, ReSharper will automatically reorder your class members.
1: ReSharper Type Members XSD Schema
对于 C#,您可以使用 Regionerate 来组织代码。 您可以创建一个仅组织代码但不使用区域的模板。
For C# you can use Regionerate to organize your code. You can create a template that simply organizes your code but doesn't use regions.
您可以使用 Devexpress' 免费 DXCore 产品(用于创建 CodeRush)。
You can create such a function yourself using Devexpress' free DXCore product (the same extensibility framework used to create CodeRush).
从 Visual Studio 中(17.7.2 不知道有多早)突出显示要排序的行,从菜单:编辑\高级\排序行(Shift+Alt+L、Shift+Alt+S)
仅按字母顺序包括返回类型方法/属性,但这是一个无需安装其他扩展的开始。
From within visual studio (17.7.2 not sure how earlier) highlight the lines to sort, from the menu: Edit\Advanced\Sort Lines (Shift+Alt+L, Shift+Alt+S)
Only does it alphabetically including return types for methods/properties, but it's a start without installing other extensions.