Bug Report T660291
Visible to All Users

Formatting - The formatting engine incorrectly handles code constructions inside object initializers

created 7 years ago

Prior to formatting (and what is desired):

C#
ContentAvailabilityGroup[] results = cacheContentGroups .Select(cacheGroup => new ContentAvailabilityGroup() { ExternalId = cacheGroup.ExternalId, Availabilities = cacheGroup.GetSpecificMatches(request) .Select(availability => availabilityFactory.Build(availability)) .ToArray(), }) .ToArray();

After formatting (not desired):

C#
ContentAvailabilityGroup[] results = cacheContentGroups .Select(cacheGroup => new ContentAvailabilityGroup() { ExternalId = cacheGroup.ExternalId, Availabilities = cacheGroup.GetSpecificMatches(request) .Select(availability => availabilityFactory.Build(availability)) .ToArray(), }) .ToArray();

How do I get the desired formatting? I get the correct formatting when my object is created outside of a Select lambda expression.

This is with chained method formatting turned off because if chained method is turned on, then the .ToArray ends up not being indented at all (which would be another bug, I suppose).

Comments (3)
AE AE
Alex Eg (DevExpress) 7 years ago

    Hi Jason,
    Thank you for the code sample. It seems that our formatting engine doesn't correctly handle code constructions inside lambda expressions. We are researching the issue in detail to find possible ways to improve the code formatting. Thank you for your patience.

      I've discovered it's not just lambdas. Any kind of initializer inside of a call seems to have issues.

      This:

      C#
      var results = await ContentConsumer.GetContentsAsync(new ContentRequest() { ContentIds = contentIds, DisplayDate = displayForDate, MaxTemplateDepth = depth, });

      Becomes this:

      C#
      var results = await ContentConsumer.GetContentsAsync(new ContentRequest() { ContentIds = contentIds, DisplayDate = displayForDate, MaxTemplateDepth = depth, });

      I do want to say that the formatting engine is coming across really nicely, and I can live with the issues I've discovered so far. I'm still tweaking to determine the difference between bugs, missing features, and need of config changes. I'm super glad that it looks like I won't need to renew my subscription to a certain other tool that does formatting that also destroys performance despite all other features being turned off.

      AE AE
      Alex Eg (DevExpress) 7 years ago

        Jason,
        Thank you for another sample - it will help us in our research. Let me take a moment and thank you for your valuable feedback that helps us make our formatting engine better!

        Answers approved by DevExpress Support

        created 7 years ago (modified 7 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.

          Comments (2)

            I'm so happy this is working.

            AE AE
            Alex Eg (DevExpress) 7 years ago

              You are welcome, Jason!

              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.