/* * SPDX-License-Identifier: AGPL-3.0-or-later * Copyright (C) 2025 Sergej Görzen * This file is part of xAPI4Unity. */ using System; using System.Collections.Generic; using System.Linq; namespace xAPI4Unity.Editor.Types { /// /// Represents a resolved tuple type, which is a combination of multiple element types. /// Extends to provide tuple-specific functionality. /// public class ResolvedTuple : ResolvedType { /// /// Indicates that this type is a tuple. /// public override bool IsTuple => true; /// /// The size of the tuple, based on the number of elements. /// public int Size => Elements.Count; /// /// A list of resolved types that make up the tuple. /// public IReadOnlyList Elements { get; } /// /// Initializes a new instance of the class with the given elements. /// /// The list of resolved types that make up the tuple. /// The string definition of the tuple. /// Thrown if the elements list is null or empty. public ResolvedTuple(IReadOnlyList elements, string definition) : base(typeof(ResolvedTuple), definition) { if (elements == null || elements.Count == 0) throw new ArgumentException("Tuple needs at least one element."); Elements = elements; } /// /// Returns the syntax representation of the tuple type. /// Combines the syntax of all element types into a tuple-like structure (e.g., "(int, float, string)"). /// /// The syntax of the tuple type as a string. public override string GetTypeSyntax() { return "(" + string.Join(",", Elements.Select(e => e.GetTypeSyntax())) + ")"; } } }