Bug 10615 - "Visual Studio" policy for C# formatting has incongruent defaults
Summary: "Visual Studio" policy for C# formatting has incongruent defaults
Status: RESOLVED FIXED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: Text Editor ()
Version: 4.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Mike Krüger
URL:
Depends on:
Blocks:
 
Reported: 2013-02-23 21:16 UTC by Erik Rogers
Modified: 2013-04-09 13:38 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Erik Rogers 2013-02-23 21:16:29 UTC
Description of Problem: Some of the defaults for the "Visual Studio" policy in Xamarin Studio do not match up with the actual C# formatting of Visual Studio. Users that select this policy expect their code to format identically to the way Visual Studio would format it. However, there are some incongruous results when using this policy in Xamarin Studio.

One such example is that "Whitespace->before opening bracket" is checked by default for both Indexers and Element Access. This is incorrect, as Visual Studio does not place leading whitespace before the opening bracket in these cases.

Steps to reproduce the problem:
1. In Preferences, set your C#/Text File code formatting to "Visual Studio".
2. Open or create a new C# project/solution.
3. Open or create a new code file that uses indexers or element access.
4. Press CTRL+I (or Edit->Format->Format Document) to see the incorrect formatting take place.

In my example, I use a Regex pattern with capture groups to illustrate the formatting mistake.

Actual Results:

var key = match.Groups ["Key"].Value;

Expected Results:

var key = match.Groups["Key"].Value;

How often does this happen? 

Every time you use the default "Visual Studio" policy and Indexers/Element Access in your code.


Additional Information: It is possible to fix this manually of course. You can uncheck "Whitespace->before opening bracket" for both Indexers and Element Access, and it will format properly. However, the default policy for "Visual Studio" should mimic the expectations that users coming from VS would have.
Comment 1 Mike Krüger 2013-02-24 03:09:53 UTC
fixed
Comment 2 Peter Hultqvist 2013-04-06 09:06:36 UTC
I discovered this bug too in master branch(from yesterday) and XS 4.0.3.

Whitespace before indexer is still the default in "Microsoft Visual Studio"
Comment 3 Peter Hultqvist 2013-04-06 09:12:51 UTC
While at it.
Same policy should not state that catch is placed on the same line.
In Visual Studio it usually is written

    }
    catch(Exception)
    {

So at lease allow both should be the default
Comment 4 Peter Hultqvist 2013-04-06 09:24:19 UTC
The following should change in the "Microsoft Visual Studio" policy.
Tested with Visual Studio 2010.
My suggestion below is based on the result of "Format Document", less strict coding can be done if not used.

Place on new line: (current policy)->(should be)
else: always same->always new
catch: always same->always new
finally: always same->always new
while: always same->allow both
Place array initializers on new line: "wrap if too long"->"do not change"
Comment 5 Mike Krüger 2013-04-09 13:38:52 UTC
I fixed the allman formatting defaults.

btw. for new issues open new bugs - if I wouldn't have memorized that there were issues with that I would've overlooked it.