#nullable enable using IPA.Utilities; using System; using System.Collections; using System.Collections.Generic; using System.Linq; namespace IPA.Config.Data { /// /// A list of s for serialization by an . /// Use or to create. /// public sealed class List : Value, IList { private readonly List values = new(); internal List() { } /// /// Gets the value at the given index in this . /// /// the index to retrieve the at /// the at /// public Value? this[int index] { get => values[index]; set => values[index] = value; } /// /// Gets the number of elements in the . /// /// public int Count => values.Count; bool ICollection.IsReadOnly => ((IList)values).IsReadOnly; /// /// Adds a to the end of this . /// /// the to add /// public void Add(Value? item) => values.Add(item); /// /// Adds a range of s to the end of this . /// /// the range of s to add public void AddRange(IEnumerable vals) { if (vals is null) throw new ArgumentNullException(nameof(vals)); foreach (var val in vals) Add(val); } /// /// Clears the . /// /// public void Clear() => values.Clear(); /// /// Checks if the contains a certian item. /// /// the to check for /// if the item was founc, otherwise /// public bool Contains(Value? item) => values.Contains(item); /// /// Copies the s in the to the in . /// /// the to copy to /// the starting index to copy to /// public void CopyTo(Value?[] array, int arrayIndex) => values.CopyTo(array, arrayIndex); /// /// Gets an enumerator to enumerate the . /// /// an for this /// public IEnumerator GetEnumerator() => ((IList)values).GetEnumerator(); /// /// Gets the index that a given is in the . /// /// the to search for /// the index that the was at, or -1. /// public int IndexOf(Value? item) => values.IndexOf(item); /// /// Inserts a at an index. /// /// the index to insert at /// the to insert /// public void Insert(int index, Value? item) => values.Insert(index, item); /// /// Removes a from the . /// /// the to remove /// if the item was removed, otherwise /// public bool Remove(Value? item) => values.Remove(item); /// /// Removes a at an index. /// /// the index to remove a at /// public void RemoveAt(int index) => values.RemoveAt(index); /// /// Converts this into a human-readable format. /// /// a comma-seperated list of the result of wrapped in square brackets public override string ToString() => $"[{string.Join(",",this.Select(v => v?.ToString() ?? "null").StrJP())}]"; IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); } }