Telerik blogs
In our previous blog posts on the JustCode Formatter ("Introducing the Formatter" and "Comparing the JustCode Formatter to the Visual Studio Formatter") we showed you what it is and how it works. Our latest post on the formatter detailed the first half of the settings for C#.  In this post, we will show the rest of the code style settings for C#. 

Code Style settings for C#

As a reminder from our last blog post, there are ten categories for C# Code Style Settings.:
  • General
  • Indentation
  • Spacing
  • New Lines
  • Blank Lines
  • Ordering
  • Brace Positioning
  • Wrapping
  • Using Directives
  • Naming Conventions
In this post, we will look at the last five categories – Ordering, Brace Positioning, Wrapping, Using Directives, and Naming Conventions.

Ordering

JustCode ordering page image
Image 1. Ordering page.

The Ordering page (shown in Image 1) allows you to define the order that code elements are arranged in your code.  The JustCode “Code Cleaner” step “Reorder and Format code” will reorder your code according to the order defined in the settings page. 

There are two groupings for ordering - File/Namespace elements and Types. You use the list boxes to define the order of the code elements, moving items up and down by selecting them and using the “Up” or “Down” buttons.

Elements can also be split by access and/or static modifiers. To add the additional level of detail to the ordering, right click on a given option in the list and choose the split type(s) from the context menu (as shown in Image 2). 

You can merge the split elements back into a single element by selecting “Merge” from the context menu, essentially reversing the split process.

Split by access image
Image 2. Split by access the selected item.

Brace Positions

Brace Position page image
Image 3. Brace Position page.

Brace positioning preferences vary as widely anyone can imagine.  JustCode extends Visual Studio functionality and provides the ability to individually customize the location of opening braces for many different types of code blocks (see Image 3). You can choose from three options where to position the opening brace for each code block: on the same line, on a new line, or indented on a new line. 

The three options are illustrated in the image below (Image 4).

Brace position options image
Image 4. Brace position options.

Wrapping

Wrapping page image
Image 5. Wrapping page.

JustCode allows customization of line wrapping by code construct, which far exceeds the way Visual Studio handles line wrapping. A few of the options are shown in Image 5. As with the other Code Style settings, the Wrapping Settings preview the changes at the bottom of the page. 

By default the max line length is set to 9999, which is essentially no wrapping.  Changing this value to a smaller value will enable your code to fit on your screen.

The option “Preserve new lines when wrapping” will preserve manually added wrapping when wrapping occurs.

All of the code constructs accept options for Wrapping - many others also accept options for Indentation as well as whether the first option is included or not.

“Wrap” - defines how exactly the wrap should be performed. You can choose from the following options:
  • No wrap: No wrapping will be performed;
  • Wrap: Depends on the value of the “First Included” check-box
  • If “First Included” is checked, the first element is wrapped
  • If “First Included” is not checked, the first element will remain on the first line, and the second element will be placed on a new line;
  • Wrap when needed: Elements which exceed the “Max Line Length” will be placed on a new line;
  • Wrap all: Each of the elements will be placed on a new line;
  • Wrap all when needed: Each of the elements will be placed on a new line if some of them exceed “Max Line Length”.
“Indent” - defines how the elements will be indented (shown in Image 6):
  • Indent: the indentation of the wrapped element is calculated based on the parent code construct.
  • Intent at column: the wrapped element will be placed on a new line under the previous element. 
“First Included” – If selected, the first element should be included in the wrapping.

Indentation options image
Image 6. Indentation options.

Using Directives

Using directives image
Image 7. Using Directives

C# Code files typically include “using” statements for commonly used namespaces.  JustCode already provides functionality to organize the using statements in a file, project, or whole solution via the “Organize and Add Missing Usings” command (available from the context menu as well as the visual aid) or the “Code Cleaner” feature.

In addition to that functionality, the Using Directives page (see Image 7) allows you to set a number of namespaces  which will always be imported when JustCode executes those commands. You can also add a list of namespaces  which should never be removed by JustCode.

Naming Conventions

Naming conventions page image
Image 8. Naming conventions page.

The Naming Conventions page defines naming conventions enforced as part of the Code Style feature. Additionally, code creation features will use these naming conventions when the code is created.  Secondary rules can be added as well, as shown for Methods.  The secondary rules are used in checking for naming validity, but not in code generation. More details about the naming conventions can be found in the Naming Convetions blog post.

The Q3 2012 release added improvements to the Naming Conventions process. JustCode will show you a warning if you type a name that goes against the defined naming conventions as long as the acronym typed is longer than two chars. You can add exceptions to this by adding acronyms in “Allowed Acronyms”, separated by a comma or a space.

Summary

We welcome you to experiment with the Code Style settings. We are confident you’ll be able to make your code look exactly like you want it. Your previous settings are safe with JustCode’s Visual Studio Cloud Backup - just be sure to create a backup before you begin.

If you have a suggestion for more customization, please leave us feedback on the JustCode Feedback Portal. You can also write to us in the forum as well as contact support directly.

Happy Coding!

The JustCode team


JustCode download banner image

About the Author

Borislav Kulov

 he has more than 10 years of experience in the development field. Borislav is a motorcycle enthusiast and in his free time he enjoys swimming and other sports.

Comments

Comments are disabled in preview mode.