From 99f369a707db596d23d71ad1317aca79a9e6f92f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Fri, 31 Dec 2021 10:30:57 +0100 Subject: [PATCH] fix: correctly check for last token if there are optionals --- .../Data/Parameters.cs | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Core/NosSmooth.PacketSerializersGenerator/Data/Parameters.cs b/Core/NosSmooth.PacketSerializersGenerator/Data/Parameters.cs index 32bf98a1371dbba60fb2535fc9253265b67e2dec..32da6c21acb9678fc7d05015b255b95646bd2ef7 100644 --- a/Core/NosSmooth.PacketSerializersGenerator/Data/Parameters.cs +++ b/Core/NosSmooth.PacketSerializersGenerator/Data/Parameters.cs @@ -4,6 +4,8 @@ // Copyright (c) František Boháček. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using NosSmooth.PacketSerializersGenerator.Extensions; + namespace NosSmooth.PacketSerializersGenerator.Data; /// @@ -38,20 +40,33 @@ public class Parameters /// /// Gets the next processing parameter. /// - public ParameterInfo Next => List[CurrentIndex]; + public ParameterInfo? Next => CurrentIndex < List.Count - 1 ? List[CurrentIndex + 1] : null; /// /// Gets the previous processing parameter. /// - public ParameterInfo Previous => List[CurrentIndex]; + public ParameterInfo? Previous => CurrentIndex > 0 ? List[CurrentIndex - 1] : null; /// /// Gets whether the current parameter is the last one. /// - public bool IsLast => CurrentIndex == List.Count - 1; + public bool IsLast => CurrentIndex == List.Count - 1 || IsRestOptionals(); /// /// Gets whether the current parameter is the first one. /// public bool IsFirst => CurrentIndex == 0; + + private bool IsRestOptionals() + { + for (int i = CurrentIndex + 1; i < List.Count - 1; i++) + { + if (!List[i].IsOptional()) + { + return false; + } + } + + return true; + } } \ No newline at end of file