Bug Report T531031
Visible to All Users

Formatting - Array initializers are formatted incorrectly

created 8 years ago

Hi again, thanks for the previous fixes!!!

I've just noticed what I think is a new section in the options -- C# \ Formatting \ Wrapping.

I've been playing around with the numbers in there and the ARRAY Initializer seems to not work 100% . The values I set, it seems to work correctly when the array is initialized within a method, but when it's initialized in the class - e.g. static array, the formatting is wrong.

I have the following settings on:

Open Brace, Wrap, Before, Align Declaration, Indent 0
Close Brace, Wrap, -----, Align Declaration, Indent 0
Wrap seperator, Wrap, After, Align Declaration, Indent ONE

When it's set like this the lines are wrapped as expected but they are all the way to the left - right against the line numbers. When I have the align by set to "Declaration Name " then they are about 100+ characters to the right.

I've tried this with both Tabs & spaces set for the 4 spaces. Same result!

As I say, within a method the formatting appears correct at first -- see later.

NOTE - I've not checked the Collection / Object initializers - but I guess they might be the same as the options are the same and I guess they will use the same code. (will check after this post).

Below are the before & after with the above settings.

C#
namespace MyNameSpace { internal class MyClass { private static readonly string[] _acceptedToolKeys = { "&Unselect All", "Consolidate", "Single", "Select A&ll", "Show A&ll", "Snapshot", "&Summary", "Where Used", "Apply Filter", "Add To Order" }; private MyClass() { } private void MethodNameHere() { string[] moreToolKeys = { "Select A&ll", "Show A&ll", "Snapshot", "&Summary", "Where Used", "Apply Filter", "Add To Order" }; } } }

AFTER CODE CLEAN UP:

C#
namespace MyNameSpace { internal class MyClass { private static readonly string[] _acceptedToolKeys = { "&Unselect All", "Consolidate", "Single", "Select A&ll", "Show A&ll", "Snapshot", "&Summary", "Where Used", "Apply Filter", "Add To Order" }; private MyClass() { } private void MethodNameHere() { string[] moreToolKeys = { "Select A&ll", "Show A&ll", "Snapshot", "&Summary", "Where Used", "Apply Filter", "Add To Order" }; } } }

WITH Align By set to Declaration Name - this seemed to work OK in the above test — but worked out why…

If I have some long XML comment above the static string… the text is all the way to the right! e.g. (beware of wrapping in post)

C#
/// <summary> /// This should be moved to check a flag within ascforms, as the use of the names here restricts internationalisation and is clumsy /// </summary> private static readonly string[] _acceptedToolKeys = { "&Unselect All", "Consolidate", "Single", "Select A&ll", "Show A&ll", "Snapshot", "&Summary", "Where Used", "Apply Filter", "Add To Order" };

OH, I've just noticed - If I paste the same above XML comment above the string[] line WITHIN the method, the text is all the way to the right as well (no matter what the align by is set to.)

Here is the new unformatted class, with comments in:

C#
namespace MyNameSpace { internal class MyClass { /// <summary> /// This should be moved to check a flag within ascforms, as the use of the names here restricts internationalisation and is clumsy /// </summary> private static readonly string[] _acceptedToolKeys = { "&Unselect All", "Consolidate", "Single", "Select A&ll", "Show A&ll", "Snapshot", "&Summary", "Where Used", "Apply Filter", "Add To Order" }; private MyClass() { } /// <summary> /// This should be moved to check a flag within ascforms, as the use of the names here restricts internationalisation and is clumsy /// </summary> private void MethodNameHere() { /// <summary> /// This should be moved to check a flag within ascforms, as the use of the names here restricts internationalisation and is clumsy /// </summary> string[] moreToolKeys = { "Select A&ll", "Show A&ll", "Snapshot", "&Summary", "Where Used", "Apply Filter", "Add To Order" }; } } }

Hope this all makes sense. I'll check the collection & Object initializers as well.

Thanks
Alan

Show previous comments (7)
AM AM
Alan Middleton999 8 years ago

    Hi Alex.

    Apologies for the delay in replying, I've not had the time to test this until now.

    The Array & Collection formatting seems to work as it should, can't see anything wrong with them, however there is still an issue with the Object Initialiser formatting. The "Align By" field doesn't make any difference to the object format - it's always formatted by Declaration - when set to Declaration name the code is not indented as it is on the other 2 types (array/collection).

    Also for the Object Formatting - If I put the Wrap Separation to wrap BEFORE it looks like this: It seems to be putting a New line after the comma

    Looking at the example you have on the options it looks like this (align by Declaration Name, wrap before separator):

    C#
    var country = new Country() { Name = "Iceland" , Area = 102775 , Population = 332529 };

    but it actually formats like this:

    C#
    private static Country country = new Country() { Name = "Iceland" , Area = 102775 , Population = 332529 };

    Still left aligned (declaration), but the commas in this case seem to be indented. Something still strange on the Object formatting… However for me - the default formatting is fine (declaration and comma after the text).

    Hope this helps.

    AM AM
    Alan Middleton999 8 years ago

      Hi Alex,

      Just spotted something else with the formatting, but not sure if you want to split this off into a different ticket or not.

      I have the following bit of code:

      C#
      FormUtils.ControlInvokeActionAsync(textBoxBlendHeaderID, () => { textBoxBlendHeaderID.Focus(); });

      Every time I press the code clean up button the bottom 3 lines of the above code gets indented by ONE SPACE

      After one press:

      C#
      FormUtils.ControlInvokeActionAsync(textBoxBlendHeaderID, () => { textBoxBlendHeaderID.Focus(); });

      After pressing 15 times:

      C#
      FormUtils.ControlInvokeActionAsync(textBoxBlendHeaderID, () => { textBoxBlendHeaderID.Focus(); });

      I have found that this issue stops and doesn't happen if I UNTICK the "Parameters" formatting wrapping option. So only when this is ticked it does the above.

      My settings for Parameters are currently;

      Tolerance : 0  and No wrap at all

      Further testing shows if I set Wrap Open Paren to NO Wrap or "Wrap if long/multiline) then the problem happens, if set to wrap then it doesn't happen.

      (Please move this to a new ticket if you wish).

      DevExpress Support Team 8 years ago

        Alan,

        Thank you, I have managed to replicate this issue and we are going to work on fixing it.
        Please give us some time.
        I have created separate ticket on your behalf: Formatting - lambda expression is incorrectly indented

        Answers approved by DevExpress Support

        created 8 years ago

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.