// // Parameters.cs // // 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.AttributeGenerators; using NosSmooth.PacketSerializersGenerator.Extensions; namespace NosSmooth.PacketSerializersGenerator.Data; /// /// Contains set of parameters of a packet. /// public class Parameters { /// /// Initializes a new instance of the class. /// /// The list of the parameters. public Parameters(IReadOnlyList parameters) { List = parameters; } /// /// Gets the list of the parameters. /// public IReadOnlyList List { get; } /// /// Gets the current index of the parameter. /// public int CurrentIndex { get; set; } /// /// Gets the currently processing parameter. /// public ParameterInfo Current => List[CurrentIndex]; /// /// Gets the next processing parameter. /// public ParameterInfo? Next => CurrentIndex < List.Count - 1 ? List[CurrentIndex + 1] : null; /// /// Gets the previous processing parameter. /// 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 || 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; i++) { if (!List[i].IsOptional() && List[i].Attributes.All(x => x.FullName != PacketConditionalIndexAttributeGenerator.PacketConditionalIndexAttributeFullName)) { return false; } } return true; } }