Skip to content

Commit e2d0124

Browse files
committed
fixed: dadhi#434 for CSharpOutput
1 parent 005b689 commit e2d0124

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

+19-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ THE SOFTWARE.
2828
// #define LIGHT_EXPRESSION
2929
#if DEBUG && NET6_0_OR_GREATER
3030
#define DEBUG_INFO_LOCAL_VARIABLE_USAGE
31-
#define DEMIT
31+
// #define DEMIT
3232
#endif
3333
#if LIGHT_EXPRESSION
3434
#define SUPPORTS_ARGUMENT_PROVIDER
@@ -8330,8 +8330,10 @@ private static StringBuilder ToCSharpString(this IReadOnlyList<MemberBinding> bi
83308330
StringBuilder sb, EnclosedIn enclosedIn, ref SmallList4<NamedWithIndex> named,
83318331
int lineIndent = 0, bool stripNamespace = false, Func<Type, string, string> printType = null, int indentSpaces = 4, ObjectToCode notRecognizedToCode = null)
83328332
{
8333-
foreach (var b in bindings)
8333+
var count = bindings.Count;
8334+
for (var i = 0; i < count; i++)
83348335
{
8336+
var b = bindings[i];
83358337
sb.NewLineIndent(lineIndent);
83368338
sb.Append(b.Member.Name).Append(" = ");
83378339

@@ -8350,25 +8352,33 @@ private static StringBuilder ToCSharpString(this IReadOnlyList<MemberBinding> bi
83508352
else if (b is MemberListBinding mlb)
83518353
{
83528354
sb.Append("{");
8353-
foreach (var i in mlb.Initializers)
8355+
var elemInits = mlb.Initializers;
8356+
var elemCount = elemInits.Count;
8357+
for (var e = 0; e < elemCount; e++)
83548358
{
8359+
var args = elemInits[e].Arguments;
83558360
sb.NewLineIndent(lineIndent + indentSpaces);
8356-
if (i.Arguments.Count > 1)
8361+
var manyArgs = args.Count > 1;
8362+
if (manyArgs)
83578363
sb.Append("(");
83588364

83598365
var n = 0;
8360-
foreach (var a in i.Arguments)
8361-
a.ToCSharpString((++n > 1 ? sb.Append(", ") : sb), EnclosedIn.ParensByDefault, ref named,
8366+
foreach (var arg in args)
8367+
arg.ToCSharpString((++n > 1 ? sb.Append(", ") : sb), EnclosedIn.ParensByDefault, ref named,
83628368
lineIndent + indentSpaces, stripNamespace, printType, indentSpaces, notRecognizedToCode);
83638369

8364-
if (i.Arguments.Count > 1)
8370+
if (manyArgs)
83658371
sb.Append(")");
83668372

8367-
sb.Append(",");
8373+
if (e < elemCount - 1)
8374+
sb.Append(",");
83688375
}
83698376
sb.NewLineIndent(lineIndent + indentSpaces).Append("}");
83708377
}
8371-
sb.Append(",");
8378+
8379+
// don't place comma after the last binding
8380+
if (i < count - 1)
8381+
sb.Append(",");
83728382
}
83738383
return sb;
83748384
}

test/FastExpressionCompiler.UnitTests/TestTools.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#if DEBUG
2-
#define PRINTIL
2+
// #define PRINTIL
33
#define PRINTCS
44
#endif
55
using System;

0 commit comments

Comments
 (0)