Skip to content

Commit 3d42bdf

Browse files
committed
fix the Switch to C# printer
1 parent 3a04eed commit 3d42bdf

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6122,6 +6122,7 @@ public static StringBuilder ToCSharpString(this Expression e, StringBuilder sb,
61226122
if (x.Value.GetType() != x.Type) // add the cast
61236123
sb.Append('(').Append(x.Type.ToCode(stripNamespace, printType)).Append(')');
61246124

6125+
// value output may also add the cast for the primitive values
61256126
return sb.Append(x.Value.ToCode(CodePrinter.DefaultConstantValueToCode, stripNamespace, printType));
61266127
}
61276128
case ExpressionType.Parameter:
@@ -6482,30 +6483,28 @@ void PrintPart(Expression part)
64826483
{
64836484
var x = (SwitchExpression)e;
64846485
sb.Append("switch (");
6485-
x.SwitchValue.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant);
6486-
sb.Append(") {");
6486+
x.SwitchValue.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant).Append(')');
6487+
sb.NewLine(lineIdent, identSpaces).Append('{');
64876488

64886489
foreach (var cs in x.Cases)
64896490
{
6490-
sb.NewLineIdent(lineIdent);
64916491
foreach (var tv in cs.TestValues)
64926492
{
6493-
sb.Append("case ");
6494-
tv.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant);
6495-
sb.Append(':');
6496-
sb.NewLineIdent(lineIdent);
6493+
sb.NewLineIdent(lineIdent).Append("case ");
6494+
tv.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant).Append(':');
64976495
}
6498-
6499-
cs.Body.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant);
6496+
6497+
sb.NewLineIdent(lineIdent + identSpaces);
6498+
cs.Body.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant).AddSemicolonIfFits();
65006499
}
65016500

65026501
if (x.DefaultBody != null)
65036502
{
6504-
sb.NewLineIdent(lineIdent).Append("default:");
6505-
x.DefaultBody.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant);
6503+
sb.NewLineIdent(lineIdent).Append("default:").NewLineIdent(lineIdent + identSpaces);
6504+
x.DefaultBody.ToCSharpString(sb, lineIdent, stripNamespace, printType, identSpaces, tryPrintConstant).AddSemicolonIfFits();
65066505
}
65076506

6508-
return sb.NewLineIdent(lineIdent).Append("}");
6507+
return sb.NewLine(lineIdent, identSpaces).Append("}");
65096508
}
65106509
case ExpressionType.Default:
65116510
{

0 commit comments

Comments
 (0)