32 lines
850 B
C#
32 lines
850 B
C#
namespace Qrakhen.Qamp.Core.Values.Objects;
|
|
|
|
public class Array(IEnumerable<Value> data) : Obj(ValueType.Array)
|
|
{
|
|
public List<Value> Data = [..data];
|
|
|
|
public void Set(int index, Value value)
|
|
{
|
|
AssertWithinBounds(index);
|
|
Data[index] = value;
|
|
}
|
|
|
|
public Value Get(int index)
|
|
{
|
|
AssertWithinBounds(index);
|
|
return Data[index];
|
|
}
|
|
|
|
public void Add(Value value)
|
|
{
|
|
Data.Add(value);
|
|
}
|
|
|
|
private void AssertWithinBounds(int index)
|
|
{
|
|
if (index < 0 || index > Data.Count)
|
|
throw new QampException($"Can not access element at index {index}, it is outside of this array's bounds.");
|
|
}
|
|
|
|
public override string ToString() => ToString(true);
|
|
public string ToString(bool detail) => detail ? $"[{string.Join(", ", Data)}]" : $"Array[{Data.Count}]";
|
|
} |