Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -2611,6 +2611,10 @@ return Style.Language == FormatStyle::LK_JavaScript || !Left.TokenText.endswith("=*/"); if (Right.is(tok::l_paren)) { + // using (FileStream fs... + if (Style.isCSharp() && Left.is(tok::kw_using) && + Style.SpaceBeforeParens != FormatStyle::SBPO_Never) + return true; if ((Left.is(tok::r_paren) && Left.is(TT_AttributeParen)) || (Left.is(tok::r_square) && Left.is(TT_AttributeSquare))) return true; Index: clang/unittests/Format/FormatTestCSharp.cpp =================================================================== --- clang/unittests/Format/FormatTestCSharp.cpp +++ clang/unittests/Format/FormatTestCSharp.cpp @@ -165,6 +165,21 @@ "public string Host {\n set;\n get;\n}"); } +TEST_F(FormatTestCSharp, CSharpUsing) { + FormatStyle Style = getGoogleStyle(FormatStyle::LK_CSharp); + Style.SpaceBeforeParens = FormatStyle::SBPO_Always; + verifyFormat("public void foo() {\n" + " using (StreamWriter sw = new StreamWriter (filenameA)) {}\n" + "}", + Style); + + Style.SpaceBeforeParens = FormatStyle::SBPO_Never; + verifyFormat("public void foo() {\n" + " using(StreamWriter sw = new StreamWriter(filenameB)) {}\n" + "}", + Style); +} + TEST_F(FormatTestCSharp, CSharpRegions) { verifyFormat("#region aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa " "aaaaaaaaaaaaaaa long region");