Formatting: Indentation for initializer with method calls
Hello,
My team and I are currently switching from VS for mac to rider.
When it comes to formatting we are facing an issue, wich we do not have solved yet.
I have the following example code:
public class Formatting
{
public Formatting()
{
new Person {
Age = 1
}.WithName("");
new Person {
Age = 1
}.WithName("")
.WithLastName("");
}
}
internal class Person
{
public int Age { get; set; }
private string FirstName { get; set; }
private string LastName { get; set; }
public Person WithName(string name)
{
FirstName = name;
return this;
}
public Person WithLastName(string lastName)
{
LastName = lastName;
return this;
}
}
I want the formatting for the person (s) to look like this:
public Formatting()
{
// this formatting is OK as it is
new Person {
Age = 1
}.WithName("");
new Person {
Age = 1
}.WithName("")
.WithLastName("");
}
What formatting rules do i have to adjust in the rider IDE or the .editorconfig to achieve this?
Thanks
Please sign in to leave a comment.
The EditorConfigs matching your request:
Select the code in editor and then press
Alt + Enter
for Context Actions, use the auto detection feature to detect code style settings. Also, you can save the settings into IDE configuration or.editorconfig
.Thanks for the answer.
The “Detect code style settings” does not work for me. It does not detect the correct formatting. After exporting the settings to the
.editorconfig
it does not work either.The proposed solution works for the code example.
But the entry
resharper_csharp_continuous_indent_multiplier = 0
has some undesirable side effects.Examples:
So, normally I want
resharper_csharp_continuous_indent_multiplier = 1
, but not for an initializer block with more than one methods calls.Where can I see all possible settings for the .editorconfig or the .DotSettings?
The EditorConfig properties are documented in Code Style settings.
Not sure if your EditorConfig in Rider is exported correctly, by defaule the “Export settings that have default values” is disabled. It may be controlled by the other local settings (like settings in
.DotSettings
config).