Object initializer format
Does anyone know the settings to use so that object initializers are left
aligned with the declaration, like this?
Blah blah = new Blah
{
Foo = foo,
Bar = bar
};
I've experimented with the various options and the closest I can get is the braces aligned on the constructor:
Blah blah = new Blah
Blah blah = new Blah
{
Foo = foo,
Bar = bar
};
I've experimented with the various options and the closest I can get is the braces aligned on the constructor:
Blah blah = new Blah
{
Foo = foo,
Bar
= bar,
}
Please sign in to leave a comment.
--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
Whas this bug fixed?
I really would like to have my constructor like:
1) To format as in first topic message, go to Braces Layout -> Braces Layout -> Array and object initializer and set it to "At next line (BSD style)".
2) To format as in your sample, set the same parameter to "At end of line (K&R style)" and uncheck Others -> Align Multiline Constructs -> Array, object and collection initializer.
It seems, that the setting does not work as expected.
@K what exactly does not work for you here?
Hi Alexander,
Please have a look at my screenshot. There is unwanted indent even with BSD style.
Turns out, StyleCop force that... If I uninstall it, everything works fine.
Any ideas how to fix it?
I want sometime time that:
var x = new X
{
Id = 1
};
@K you might untick "ReSharper | Options | Code Editing | C# | Formatting Style | Tabs, Indents, Alignment | Align Multiline Constructs | Array, object and collection initializer" checkbox after installing the plugin.
Hi Alexander,
Yeah, that did the trick for me. Thank you.