Generated code using object initializer has no line breaks
See original GitHub issueDescribe 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:
- Created a year ago
- Reactions:2
- Comments:11 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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/roslynAs 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