RArrange
RArrange is a C# code beautifier for Visual Studio powered by Roslyn. It will automatically arrange your code based on a highly customizable configuration, always ensuring a consistent file layout.
Installation
RArrange can be installed directly from the Visual Studio Marketplace. Currently only Visual Studio 2022 is supported.
Usage
RArrange is enabled by default and will try to arrange a file when it is being saved. However, this requires the presence of a configuration file, which will be described in more detail in the next section.
Besides working on a single file, RArrange can also be applied to either a single project or the entire solution via the context menus of the Solution Explorer.
IMPORTANT while arranging a single file on save can be undone, this is not the case if RArrange is applied to a single project or the entire solution.
Configuration File
The behavior of RArrange can be extensively customized using a configuration file named rarrange.json
. The file must be located in the same directory as the solution file. It can be either created manually or by using the Solution Explorer.
- Right-click the solution in the Solution Explorer
- Select
Add -> RArrange Configuration File
The file consists of several sections that will be described in more detail.
Region Settings
The regionSettings
section configures the general usage of #region
directives.
Setting |
Description |
regions |
Determines whether to use #region directives. |
endRegionNames |
Determines whether the #endregion directives will include the name of the region. |
headerRegion |
Determines whether header comments are moved into their own dedicated region. |
headerRegionName |
The name of the optional header region. If not specified, the default name Header will be used. |
fallbackRegionName |
The name of the fallback region, i.e., the region that contains all type members not covered by any sorter. If not specified, the default name Other will be used. |
Example
"general": {
"regions": true,
"endregionNames": true,
"headerRegion": true,
"headerRegionName": "Header",
"fallbackRegionName": "Other"
}
Type Order
The typeOrder
list specifies the preferred order of types when using the type
sort order. See Types for a list of valid values.
Example
"typeOrder": [
"enum",
"interface",
"class",
"record",
"struct"
]
Access Modifier Order
The accessModifierOrder
list specifies the preferred order of access modifiers when using the accessModifier
sort order. See AccessModifiers for a list of valid values.
Example
"accessModifierOrder": [
"public",
"internal",
"protected",
"private",
"protectedInternal",
"privateProtected",
"explicitInterfaceImplementation"
]
Groups
A group is a collection of sorters and nested groups that define how type members are organized within a specified region. Each group has the following properties:
Property |
Description |
regionname |
The name of the region that will be used in the #region directives. |
groups |
A collection of nested groups that allow further hierarchical organization within this group. |
sorters |
A collection of sorters that define how individual members are sorted within this group. |
Example
{
"regionName": "Constants",
"sorters": [
{
"type": "field",
"modifiers": [
"const"
],
"sortOrder": [
"nameAscending"
]
}
]
}
Sorters
Sorters define the criteria for sorting individual members within a group. Each sorter has the following properties:
Property |
Description |
type |
Determines which type of member will be sorted. See SorterTypes for a list of valid values. |
accessmodifier |
A list of access modifiers that must match for a type member to be sorted. See AccessModifiers for a list of valid values. |
modifiers |
A list of modifiers that must match for a type member to be sorted by the sorter instance. See Modifiers for a list of valid values. |
sortorders |
A list of sort orders defining how the matched members should be sorted. See SortOrders for a list of valid values. |
Example
{
"type": "field",
"modifiers": [
"const"
],
"sortOrder": [
"nameAscending"
]
}
Types
Value |
enum |
interface |
class |
record |
struc |
Sorter Types
Value |
constructor |
conversionOperator |
delegate |
destructor |
event |
eventField |
field |
indexer |
method |
nestedType |
operator |
property |
type |
Access Modifiers
Value |
public |
internal |
protected |
private |
protectedInternal |
privateProtected |
explicitInterfaceImplementation |
Modifiers
Value |
abstract |
async |
const |
event |
extern |
new |
override |
partial |
readonly |
sealed |
static |
unsafe |
virtual |
volatile |
Sort Orders
Value |
nameAscending |
nameDescending |
parameterCountAscending |
parameterCountDescending |
accessModifier |
type |
Ignore File
RArrange includes a feature to ignore specific files or directories from being processed. This is accomplished through the use of an ignore file named .rarrangeignore
. The file must be located in the same directory as the solution file. It can be either created manually or by using the Solution Explorer.
- Right-click the solution in the Solution Explorer
- Select
Add -> RArrange Ignore File
Each line in the ignore file specifies a glob pattern. All patterns are evaluated relative to the solution directory. Lines starting with # are ignored.
Here is an overview of some common patterns.
Pattern |
Description |
dir/ |
Ignores all files in the directory dir and all its subdirectories |
dir/file.cs |
Ignores the file file.cs in the directory dir |
*.cs |
Ignores all files .cs files in the solution directory |
*file*.cs |
Ignores all .cs files with the word file in the filename |
dir/**/*.cs |
Ignores all .cs files in all subdirectories of the directory dir |
See Also
Support
To report at problem or suggest a feature visit the RArrange Issue Tracker.
Changelog
1.0.0 - 2024-06-03