Bug in C# formatting style "Place field attribute on same line"

Hi,

I like to have my code look like this:

        #region Fields
        [NotNull] private readonly IScriptRegistryService _scriptReg;
        [NotNull] private readonly IMainServerService _mainServer;
        [NotNull] private readonly XForm _mainForm;

        #endregion

So I have set the C# formatting style option "Place field attribute on same line" toggled ON.
I have also set the options "Auto-format on semicolon" and "Auto-format on closing brace" ON.

There are two situations when my "Place field attribute on same line" configurayion is not respected by R# 5.1.3:

1) When I retype the closing brace of the surrounding context of my fields.
2) When I paste some attributed fields from the clipboard.

In both theese situations my code is restructured to look like this:

        #region Fields
        [NotNull]
        private readonly IScriptRegistryService _scriptReg;
         [NotNull]

        private readonly IMainServerService _mainServer;
         [NotNull]

        private readonly XForm _mainForm;
        #endregion

Which is NOT what I want.

Is this s known bug? Any workarounds?

(Mark that R# respects my "Auto-format on semicolon" configuration when I retype the terminating semicolon of any of my attributed fields.)

Leif Erik

2 comments

Hello Leif,

Actually, it's Visual Studio that automatically reformats your code when
you paste or re-type '}' and it formats your code according to its own rules
(not ReSharpers). In order to avoid this behavior open Tools | Options |
Text Editor | C# | Formatting and turn off 'Automatically format completed
block on }' and 'Automatically format on paste' options. Thank you!

Andrey Serebryansky
Senior Support Engineer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"

Hi,

I like to have my code look like this:

+        #region Fields+
+        private readonly IScriptRegistryService _scriptReg;
private readonly IMainServerService _mainServer;
private readonly XForm _mainForm;+
+        #endregion+
So I have set the C# formatting style option "Place field attribute on
same line" toggled ON. I have also set the options "Auto-format on
semicolon" and "Auto-format on closing brace" ON.

There are two situations when my "Place field attribute on same line"
configurayion is not respected by R# 5.1.3:

1) When I retype the closing brace of the surrounding context of my
fields. 2) When I paste some attributed fields from the clipboard.

In both theese situations my code is restructured to look like this:

+        #region Fields+
+        +
+       + +private readonly IScriptRegistryService _scriptReg;
+
+       + +private readonly IMainServerService _mainServer;
+
+       + private readonly XForm _mainForm;
+        #endregion+

Which is NOT what I want.

Is this s known bug? Any workarounds?

(Mark that R# respects my "Auto-format on semicolon" configuration
when I retype the terminating semicolon of any of my attributed
fields.)

Leif Erik

---
Original message URL:
http://devnet.jetbrains.net/message/5288503#5288503



0

Thanks, that fixed it. I think it is kind of strange, though, that R# is not aware of this and overrides the built-in studio-formatting, since my R#-settings differs from what MS wants me to do.

0

Please sign in to leave a comment.