Is there a Visual Studio 2010 extension for sorting methods?

StyleCop sets a specific sort order for the contents of C # files. For example, fields must be declared before methods, and public announcements must appear before private.

It would be useful to have a Visual Studio extension to automatically move these things in that order.

Is there a good extension for this (I found CodeSorter , but reviews say it is very buggy)? Or are there any extensions or shortcuts that make it less painful to manually reorder this content?

+7
source share
5 answers

You can try Regionerate :

Regionerate is an automated tool that helps you keep yours over time. Regionerate allows you to define regions in your code and determine how members (fields, methods, properties, etc.) should be placed inside them. Regionerate - a tool with zero friction - when setting up, you can choose a code layout (the way you want the code to view) or just use the default code layout. From then on, Regionerate will make sure your code matches the code layout.

+8
source

ReSharper can do this. It has a member type mock function, which allows you to use either a default set of rules or define your own.

+5
source

CodeMaid is a free open source Visual Studio extension that will refactor code to comply with StyleCop conventions. You can find it here: http://visualstudiogallery.msdn.microsoft.com/76293c4d-8c16-4f4a-aee6-21f83a571496

Disclaimer: This is a completely shameless plugin, I wrote it.;)

+5
source

I use ReSharper and their member layout. See the section for more details.

+1
source

If sorting the code is your only problem, you can try the Visual Studio CodeSorter extension

CodeSorter is a custom extension that allows its users sort C # code itby various conditions, such as names, types (method, class, structure, ...), visibility modifiers (private, public, ...), (const, static, readonly) and virtuality modifiers (virtual, override, new, ...).

Several search criteria can be assigned the same priority, for example, protected places and private members, and then the public and internal persons.

Names are compared in such a way that "m_" and "_" are leading. This allows the following fields and properties (for example, _foo and Foo) to each other.

Single-line declarations are placed without blank line restrictions, while multi-line declarations are separated by an empty line. The exception is that a single-line field, followed by a multi-layer property without a comment with the same name, will be placed without a line separator.

0
source

All Articles