question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Generated code using object initializer has no line breaks

See original GitHub issue

Describe the bug When using object initializer syntax, every member is initialized on the same line in a string like this:

var target = new CarDto()
{Prop1 = m.Prop1, Prop2 = m.Prop2};
return target;

This makes it very hard to read the generated code and make sure the mapping is performed appropriately.

To Reproduce Generate a DTO with init properties:

public record CarDto
{
   public string Prop1 { get; init; } = "";
   public string Prop2 { get; init; } = "";
}

A standard mapping to this DTO will exhibit the above behavior.

Edit: Mappings using constructors have the same behavior.

Expected behavior Expected output has proper formatting:

var target = new CarDto()
{
   Prop1 = m.Prop1,
   Prop2 = m.Prop2
};
return target;

Environment (please complete the following information):

  • Mapperly Version: 2.3.1
  • .NET Version: .NET 7 preview 6
  • Target Framework: net7.0
  • OS: Windows 11

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

8reactions
DoctorKroliccommented, Nov 19, 2022

I am happy to announce that the underlying issue with NormalizeWhitespace API has been resolved. The fix will be available in the next version of roslyn SDK. If you find any broken cases or other bugs in this area, feel free to open new issues at dotnet/roslyn

1reaction
DoctorKroliccommented, Jan 11, 2023

As far as I know, MS.CA.* packages are bound to Visual Studio releases. So 4.5 version should become available as soon as VS 17.5 releases. But I am not completely sure about that

Read more comments on GitHub >

github_iconTop Results From Across the Web

VS2019 - Insert New Line for object, collections and array ...
Try unticking the following checkbox ReSharper | Options | Code Editing | C# | Formatting Style | Line Breaks and Wrapping | Arrangement...
Read more >
Object initializer formatting
Hi, When I auto-format my documents using Rider, object initializers are put on the same line, breaking at the max character limit for......
Read more >
Object Initializer in C# problem with readability
Stop! You have a bigger problem than the readability. It looks like you don't understand how object initializers work.
Read more >
[New Feature] Initialize Classes by Using an Object Initializer
Hi there, I come from a C# background and it has something great call Object Initializer. Which allows you to initialize an object...
Read more >
Object initializer - JavaScript - MDN Web Docs - Mozilla
An object initializer is a comma-delimited list of zero or more pairs of property names and associated values of an object, enclosed in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found