From 411279efaa6374008f1aa96bf62ee30c7fb00cec Mon Sep 17 00:00:00 2001 From: longph Date: Mon, 11 Nov 2024 02:14:22 +0200 Subject: [PATCH] Add fields length check before subtraction --- .../CodeWriters/PythonCodeWriter.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/JsonClassGeneratorLib/CodeWriters/PythonCodeWriter.cs b/JsonClassGeneratorLib/CodeWriters/PythonCodeWriter.cs index d0239be..35271bb 100644 --- a/JsonClassGeneratorLib/CodeWriters/PythonCodeWriter.cs +++ b/JsonClassGeneratorLib/CodeWriters/PythonCodeWriter.cs @@ -147,11 +147,13 @@ public void WriteClassMembers(StringBuilder sw, JsonType type, String prefix) mappingFunction.AppendLine(mappingString); fields.Append(internalPropertyAttribute + ", "); } - - // Remove trailing comma - fields.Length--; - fields.Length--; - + + // Remove trailing comma and trailing space + if (fields.Length > 0) + { + fields.Length -= 2; + } + // Write Dictionnary Mapping Functions sw.AppendLine(); sw.AppendLine(" @staticmethod");