Visual Studio 2017 Editor new line wrapping


We all have our favourite settings when it comes to setting up Visual Studio, and the editor is quite often set up differently for a group of developers working together. I like having the opening brace ({) on the same line as the class, struct or whatever the brace signals the beginning of.

I like this:

class {

as compared to this:

class {

I frequently use the key combination Ctrl+K, Ctrl+D to format my document after having typed some code. I dislike it, if the formatting is not to my liking. It should therefore not come as a surprise, if I tell you that while working on a new UWP app, in which I had copied across some code from a Template10 project template, the key combo seemingly didn’t work anymore. After some investigation, including opening an existing Console app, in which the key combo did work, I took a look at this code:

namespace Template10.Views
{
    public sealed partial class SettingsPage : Page
    {
        readonly Template10.Services.SerializationService.ISerializationService _serializationService;
 
        public SettingsPage()
        {
            InitializeComponent();
            NavigationCacheMode = NavigationCacheMode.Required;
            _serializationService = Template10.Services.SerializationService.SerializationService.Json;
        }
 
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var index = int.Parse(_serializationService.Deserialize(e.Parameter?.ToString()).ToString());
            MyPivot.SelectedIndex = index;
        }
    }
}

Because of the Page class, from which the class shown, SettingsPage, is derived has a notification stating “Base type ‘Page’ is already specified in other parts”, the class/type name Page is greyed out. This effectively blocks for the document formatting placing the opening brace { on the same line as the class declaration. If I remove : Page, and press the key combination Ctrl+K, Ctrl+D, this is what I get.

namespace Template10.Views {
    public sealed partial class SettingsPage {
        readonly Template10.Services.SerializationService.ISerializationService _serializationService;
 
        public SettingsPage() {
            InitializeComponent();
            NavigationCacheMode = NavigationCacheMode.Required;
            _serializationService = Template10.Services.SerializationService.SerializationService.Json;
        }
 
        protected override void OnNavigatedTo(NavigationEventArgs e) {
            var index = int.Parse(_serializationService.Deserialize(e.Parameter?.ToString()).ToString());
            MyPivot.SelectedIndex = index;
        }
    }
}

 

Advertisements