Join us for a free 2-day community event – JetBrains .NET Days Online 2024

Formatting code in columns

Easily read common code in column-style layout!

Ad-hoc formatting or everywhere? 📐

Aligning properties in columns can greatly improve readability for DTOs or vector data types. We can also align binary expressions, invocations and many more constructs. However, often we don't want to apply such formatting across our whole code base, but in very particular cases. Using formatter comments, we can format our code just for a specific scope:

public class PersonDto
{
    // @formatter:<setting_name> <value>
    public Guid     PersonGuid  { get; set; }
    public int      PersonId    { get; set; }
    public DateTime UtcCreated  { get; set; }
    public DateTime UtcModified { get; set; }
    public string   Name        { get; set; }
    public string   Email       { get; set; }
    public string   City        { get; set; }
    public string   State       { get; set; }
    public int      ZipCode     { get; set; }
    // @formatter:<setting_name> restore
}

In order to determine the setting_name and value, we recommend to first change the formatting through the settings dialog, save it to the solution layer, and then to identify the added line in your-solution.sln.dotsettings.

May the formatting be with you! 🧙🏻

See Also


Related Resources

Params collection in C#
Params collection in C#
Use the params collection in C# so methods can accept a dynamic number of parameters.
File-scoped namespaces and types
File-scoped namespaces and types
Organize code better and reduce bugs by using file-scoped namespaces and objects.
C# Top-level statements
C# Top-level statements
Use top-level statements in C# to reduce boilerplate code.