Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2862,6 +2862,13 @@ if (Right.is(tok::l_paren)) if (Left.is(tok::kw_using)) return spaceRequiredBeforeParens(Left); + // space between ']' and '{' + if (Left.is(tok::r_square) && Right.is(tok::l_brace)) + return true; + // space before '{' in "new MyType {" + if (Left.is(TT_Unknown) && Right.is(tok::l_brace) && Left.Previous && + Left.Previous->is(tok::kw_new)) + return true; } else if (Style.Language == FormatStyle::LK_JavaScript) { if (Left.is(TT_JsFatArrow)) return true; Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -374,5 +374,22 @@ Style); } +TEST_F(FormatTestCSharp, CSharpObjectInitializers) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + Style.SpaceBeforeParens = FormatStyle::SBPO_Always; + + verifyFormat("Shape[] shapes = new[] {\n" + " new Circle {\n" + " Radius = 2.7281,\n" + " Colour = Colours.Red,\n" + " },\n" + " new Square {\n" + " Side = 101.1,\n" + " Colour = Colours.Yellow,\n" + " },\n" + "};", + Style); +} + } // namespace format } // end namespace clang