[DevExpress Support Team: CLONED FROM T609122: Object Initialization Formatting indentation rules not followed on subsequent format of document]
A missing thing I haven't been able to figure out how to handle is nesting of indentation rules. I can't find an option to specify that I want indentation by declaration based with respect to nesting level. So if I have a method call that has a nested object initializer, for instance, indentation for the nested items all end up being reset to the original declaration's level when indenting by declaration (as does nested Call Chaining).
Jason,
Thank you for the explanations, but it would be very helpful if you provide a code sample that illustrates your case and what you want to get after formatting.
I hope this help me clearly understand your needs.
I look forward to your response.
What I'd like:
myObject.Initialize(new Request() { Property1 = mySimple, Name = "New", Property2 = activeUser.Id, PersistChanges = true }); myObject.Initialize(new Request() { Property1 = MoreComplex(new ComplexThinger() { ComplexProperty1 = thingy, ComplexProperty2 = thingy2, }, Name = "New", Property2 = activeUser.Id, PersistChanges = true }); var states = GetWorksheetStates(request) .Select(ws => { var worksheet = CreateWorksheetInstance(); worksheet.Initialize(new CreateWorksheetRequest() { CopyFromInvoiceId = ws.InvoiceId, Name = "New", PersistChanges = true, OwnerEmployeeId = _activeUser.EmployeeId, }); return worksheet; }) .ToArray();
What I can get:
myObject.Initialize(new Request() { Property1 = mySimple, Name = "New", Property2 = activeUser.Id, PersistChanges = true }); myObject.Initialize(new Request() { Property1 = MoreComplex(new ComplexThinger() { ComplexProperty1 = thingy, ComplexProperty2 = thingy2, }, Name = "New", Property2 = activeUser.Id, PersistChanges = true }); var states = GetWorksheetStates(request) .Select(ws => { var worksheet = CreateWorksheetInstance(); worksheet.Initialize(new CreateWorksheetRequest() { CopyFromInvoiceId = ws.InvoiceId, Name = "New", PersistChanges = true, OwnerEmployeeId = _invoiceProvider.ActiveUser.EmployeeId, }); return worksheet; }) .ToArray();
It looks like the formatting for the Object Initialization falls back to Parameter formatting rules. It appears that nesting is working in some cases and not others because when I built this sample it wasn't falling back to the statement level, whereas when I tried something earlier all the braces had reset back to level 1 indent no matter how deeply nested. I'll see if I can figure out what I had to get that scenario. I'm using this formatter exclusively now, so I should be able to track down issues more quickly.
Hello Jason,
Thank you for providing the code samples.
Now I understand the behavior you want and I agree that we should support it.
We need some additional time to research how we can do that, so we will notify you when we make any progress.
Hi Jason,
I would like to inform you that in the latest CodeRush version (available at Visual Studio Market Place) you can adjust formatting options to format code exactly as you want.
I have attached a screencast that illustrates how to do this.