Index: clang/lib/Format/ContinuationIndenter.cpp =================================================================== --- clang/lib/Format/ContinuationIndenter.cpp +++ clang/lib/Format/ContinuationIndenter.cpp @@ -1047,6 +1047,9 @@ if (NextNonComment->is(TT_ArraySubscriptLSquare)) { if (State.Stack.back().StartOfArraySubscripts != 0) return State.Stack.back().StartOfArraySubscripts; + // C# allows `["Key"] = value,` in braced init lists (Object initializers). + if (State.Stack.back().Tok->BlockKind == BK_BracedInit && Style.isCSharp()) + return State.Stack.back().Indent; return ContinuationIndent; } Index: clang/lib/Format/FormatToken.h =================================================================== --- clang/lib/Format/FormatToken.h +++ clang/lib/Format/FormatToken.h @@ -509,6 +509,9 @@ /// Returns \c true if this tokens starts a block-type list, i.e. a /// list that should be indented with a block indent. bool opensBlockOrBlockTypeList(const FormatStyle &Style) const { + // C# Does not indent object initialisers as continuations. + if (is(tok::l_brace) && BlockKind == BK_BracedInit && Style.isCSharp()) + return true; if (is(TT_TemplateString) && opensScope()) return true; return is(TT_ArrayInitializerLSquare) || is(TT_ProtoExtensionLSquare) || Index: clang/lib/Format/UnwrappedLineParser.cpp =================================================================== --- clang/lib/Format/UnwrappedLineParser.cpp +++ clang/lib/Format/UnwrappedLineParser.cpp @@ -1677,7 +1677,10 @@ } break; case tok::l_square: - tryToParseLambda(); + if (Style.isCSharp()) + parseSquare(); + else + tryToParseLambda(); break; case tok::l_paren: parseParens(); Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -527,14 +527,14 @@ verifyFormat(R"(// Shape[] shapes = new[] { - new Circle { - Radius = 2.7281, - Colour = Colours.Red, - }, - new Square { - Side = 101.1, - Colour = Colours.Yellow, - }, + new Circle { + Radius = 2.7281, + Colour = Colours.Red, + }, + new Square { + Side = 101.1, + Colour = Colours.Yellow, + }, };)", Style); @@ -542,8 +542,8 @@ verifyFormat(R"(// Shape[] shapes = new[] { new Circle { Radius = 2.7281, Colour = Colours.Red }, new Square { - Side = 101.1, - Colour = Colours.Yellow, + Side = 101.1, + Colour = Colours.Yellow, } };)", Style);