Search code examples
c#coding-stylexamarin-studio

How to set code formatting to allow end-of-line comments?


The C# code formatting in Xamarin Studio (i.e. when hitting Ctrl-I to format the document) puts end of line comments onto a new line. I can't find any way to change this in the C# code formatting policy settings. How to change this to preserve end of line comments on the same line?

For example, take this code:

public class Foo
{
    int bar; // comment
}

If I hit Ctrl-I (or alternately click Edit > Format > Format Document from the menu, or select the code and click Edit > Format > Format Selection from the menu), the code is reformatted as:

public class Foo
{
    int bar; 
    // comment
}

I'm using v4.2.2 build 2 v4.3 build 52 on OS X.

Note: it seems this is a bug. So my question really is -- has anyone who has also encountered this come up with a fix or workaround and if so what is it?


Solution

  • This has been acknowledged as a bug by Xamarin. See this bug report. In that report, Xamarin says it's replacing its entire formatting engine as of mid-2014, with the hope of having it in place by "next year." Xamarin further suggests avoiding the problem by turning off auto-formatting on save, suggesting there is no official fix or workaround at this time other than avoiding the issue.