@@ -8226,7 +8226,7 @@ public static string GetArithmeticBinaryOperatorMethodName(this ExpressionType n
82268226 };
82278227
82288228 [MethodImpl((MethodImplOptions)256)]
8229- internal static bool IsBlockLike (this ExpressionType nodeType) =>
8229+ internal static bool IsBracedBlockLike (this ExpressionType nodeType) =>
82308230 nodeType == ExpressionType.Try |
82318231 nodeType == ExpressionType.Switch |
82328232 nodeType == ExpressionType.Block |
@@ -8237,12 +8237,12 @@ internal static bool IsReturnable(this ExpressionType nodeType) =>
82378237 nodeType != ExpressionType.Goto &
82388238 nodeType != ExpressionType.Label &
82398239 nodeType != ExpressionType.Throw &&
8240- !IsBlockLike (nodeType);
8240+ !IsBracedBlockLike (nodeType);
82418241
82428242 [MethodImpl((MethodImplOptions)256)]
82438243 internal static bool IsBlockLikeOrConditional(this ExpressionType nodeType) =>
82448244 nodeType == ExpressionType.Conditional | nodeType == ExpressionType.Coalesce ||
8245- IsBlockLike (nodeType);
8245+ IsBracedBlockLike (nodeType);
82468246
82478247 internal static Expression StripConvertRecursively(this Expression expr) =>
82488248 expr is UnaryExpression convert && convert.NodeType == ExpressionType.Convert
@@ -9940,11 +9940,11 @@ public static class ToCSharpPrinter
99409940 {
99419941 /// <summary>Tries hard to convert the expression into the valid C# code. Avoids parens by default for the root expr.</summary>
99429942 public static string ToCSharpString(this Expression expr, EnclosedIn enclosedIn = EnclosedIn.AvoidParens) =>
9943- expr.ToCSharpString(new StringBuilder(1024), enclosedIn, stripNamespace: true).Append(';'). ToString();
9943+ expr.ToCSharpString(new StringBuilder(1024), enclosedIn, stripNamespace: true).ToString();
99449944
99459945 /// <summary>Tries hard to convert the expression into the valid C# code. Avoids parens by default for the root expr.</summary>
99469946 public static string ToCSharpString(this Expression expr, ObjectToCode notRecognizedToCode, EnclosedIn enclosedIn = EnclosedIn.AvoidParens) =>
9947- expr.ToCSharpString(new StringBuilder(1024), stripNamespace: true, notRecognizedToCode: notRecognizedToCode).Append(';'). ToString();
9947+ expr.ToCSharpString(new StringBuilder(1024), stripNamespace: true, notRecognizedToCode: notRecognizedToCode).ToString();
99489948
99499949 /// <summary>Tries hard to convert the expression into the valid C# code</summary>
99509950 public static StringBuilder ToCSharpString(this Expression e, StringBuilder sb, EnclosedIn enclosedIn = EnclosedIn.ParensByDefault,
@@ -10421,7 +10421,7 @@ void PrintPart(Expression part, ref TNamed named)
1042110421 sb.Append("return ");
1042210422 part.ToCSharpString(sb, EnclosedIn.AvoidParens, ref named,
1042310423 incIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode);
10424- sb.AppendSemicolonOnce();
10424+ sb.AppendSemicolonOnce(part );
1042510425 }
1042610426 }
1042710427
@@ -10546,13 +10546,13 @@ void PrintPart(Expression part, ref TNamed named)
1054610546 {
1054710547 var bodyIn = caseBody.Type != typeof(void) ? EnclosedIn.Return : EnclosedIn.AvoidParens;
1054810548 caseBody.ToCSharpString(bodyIn == EnclosedIn.Return ? sb.Append("return ") : sb, bodyIn, ref named,
10549- caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce();
10549+ caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce(caseBody );
1055010550 }
1055110551 }
1055210552 else
1055310553 {
1055410554 caseBody.ToCSharpString(sb, enclosedIn, ref named,
10555- caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce();
10555+ caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce(caseBody );
1055610556 sb.NewLineIndent(caseBodyIndent).Append("break;");
1055710557 }
1055810558 }
@@ -10571,13 +10571,13 @@ void PrintPart(Expression part, ref TNamed named)
1057110571 {
1057210572 var bodyIn = defaultBody.Type != typeof(void) ? EnclosedIn.Return : EnclosedIn.AvoidParens;
1057310573 defaultBody.ToCSharpString(bodyIn == EnclosedIn.Return ? sb.Append("return ") : sb, bodyIn, ref named,
10574- caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce();
10574+ caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce(defaultBody );
1057510575 }
1057610576 }
1057710577 else
1057810578 {
1057910579 defaultBody.ToCSharpString(sb, enclosedIn, ref named,
10580- caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce();
10580+ caseBodyIndent, stripNamespace, printType, indentSpaces, notRecognizedToCode).AppendSemicolonOnce(defaultBody );
1058110581 sb.NewLineIndent(caseBodyIndent).Append("break;");
1058210582 }
1058310583 }
@@ -10831,7 +10831,7 @@ private static StringBuilder ToCSharpBlock<TNamed>(this Expression expr, StringB
1083110831 sb.NewLineIndent(lineIndent + indentSpaces);
1083210832 sb = expr?.ToCSharpString(sb, EnclosedIn.ParensByDefault, ref named,
1083310833 lineIndent + indentSpaces, stripNamespace, printType, indentSpaces, notRecognizedToCode) ?? sb.Append("null");
10834- sb.AppendSemicolonOnce();
10834+ sb.AppendSemicolonOnce(expr );
1083510835 }
1083610836 return sb.NewLineIndent(lineIndent).Append('}');
1083710837 }
@@ -10841,7 +10841,7 @@ private static StringBuilder ToCSharpExpression<TNamed>(this Expression expr,
1084110841 bool newLineExpr, int lineIndent, bool stripNamespace, Func<Type, string, string> printType, int indentSpaces, ObjectToCode notRecognizedToCode)
1084210842 where TNamed : struct, ISmallList<NamedWithIndex>
1084310843 {
10844- if (!expr.NodeType.IsBlockLike ())
10844+ if (!expr.NodeType.IsBracedBlockLike ())
1084510845 {
1084610846 if (!newLineExpr)
1084710847 return expr.ToCSharpString(sb, enclosedIn, ref named,
@@ -10870,8 +10870,8 @@ private static StringBuilder ToCSharpExpression<TNamed>(this Expression expr,
1087010870 return sb.NewLineIndent(lineIndent).Append("})");
1087110871 }
1087210872
10873- internal static StringBuilder AppendSemicolonOnce(this StringBuilder sb) =>
10874- sb[sb.Length - 1] != ';' ? sb.Append(";") : sb;
10873+ internal static StringBuilder AppendSemicolonOnce(this StringBuilder sb, Expression expr = null ) =>
10874+ expr?.NodeType.IsBracedBlockLike() == true ? sb : sb[sb.Length - 1] != ';' ? sb.Append(";") : sb;
1087510875
1087610876 internal static StringBuilder AppendNewLineOnce(this StringBuilder sb)
1087710877 {
@@ -11099,7 +11099,7 @@ private static StringBuilder BlockToCSharpString<TNamed>(this BlockExpression b,
1109911099 }
1110011100 }
1110111101
11102- if (lastExpr.NodeType.IsBlockLike () ||
11102+ if (lastExpr.NodeType.IsBracedBlockLike () ||
1110311103 lastExpr is DefaultExpression d && d.Type == typeof(void))
1110411104 {
1110511105 lastExpr.ToCSharpString(sb, EnclosedIn.Block, ref named,
0 commit comments