Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Nov 4, 2024
1 parent f44c75e commit aaffa8e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Kiota.Builder/Writers/TypeScript/CodeFunctionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ private void WriteComposedTypeSerializer(CodeFunction codeElement, LanguageWrite
{
var paramName = composedParam.Name.ToFirstCharacterLowerCase();
writer.WriteLine($"if ({paramName} === undefined || {paramName} === null) return;");
int pos = 0;
bool isFirst = true;
foreach (var type in composedType.Types.Where(x => IsPrimitiveType(x, composedType, false)))
{
var ifElse = pos == 0 ? "" : "else ";
var ifElse = isFirst ? "" : "else ";
WriteCaseStatementForPrimitiveTypeSerialization(type, "undefined", paramName, codeElement, writer, ifElse);
pos++;
isFirst = false;
}
return;
}
Expand Down Expand Up @@ -433,10 +433,10 @@ private void WriteComposedTypeIfClause(CodeComposedTypeBase composedType, CodeFu
var isCollectionOfEnum = IsCollectionOfEnum(codeProperty);
var spreadOperator = isCollectionOfEnum ? "..." : string.Empty;

var pos = 0;
bool isFirst = true;
foreach (var type in composedType.Types.Where(x => IsPrimitiveType(x, composedType)))
{
var isElse = pos == 0 ? "" : "else ";
var isElse = isFirst ? "" : "else ";
var nodeType = conventions.GetTypeString(type, method, false);
var serializationName = GetSerializationMethodName(type, method.OriginalLocalMethod);
if (string.IsNullOrEmpty(serializationName) || string.IsNullOrEmpty(nodeType)) return;
Expand All @@ -447,7 +447,7 @@ private void WriteComposedTypeIfClause(CodeComposedTypeBase composedType, CodeFu

writer.WriteLine($"writer.{serializationName}(\"{codeProperty.WireName}\", {spreadOperator}{modelParamName}.{codePropertyName}{defaultValueSuffix} as {nodeType});");
writer.CloseBlock();
pos++;
isFirst = false;
}
}

Expand Down

0 comments on commit aaffa8e

Please sign in to comment.