39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System;
|
|
|
|
namespace Qrakhen.Qamp.Core.Values.Objects;
|
|
|
|
public class Array(IEnumerable<Value> data) : ItemProvider<int>(ValueType.Array)
|
|
{
|
|
public Value[] Data = [..data];
|
|
protected override void InnerSet(int index, Value value)
|
|
{
|
|
Data[index] = value;
|
|
}
|
|
|
|
protected override Value InnerGet(int index)
|
|
{
|
|
return Data[index];
|
|
}
|
|
|
|
protected override void AssertValidAccesor(int index)
|
|
{
|
|
if (index < 0 || index > Data.Length)
|
|
throw new ItemProviderException($"Can not index '{index}' of array, as the index is outside its boundaries.", this);
|
|
}
|
|
|
|
protected override int ExtractIndex(Value value)
|
|
{
|
|
int index;
|
|
if (value.IsSigned)
|
|
index = (int)value.Signed;
|
|
else if (value.IsUnsigned)
|
|
index = (int)value.Unsigned;
|
|
else
|
|
throw new ItemProviderException($"Can not use {value} as an accessor, as it is not an integer.", this);
|
|
|
|
return index;
|
|
}
|
|
|
|
public override string ToString() => ToString(true);
|
|
public string ToString(bool detail) => detail ? $"[{string.Join(", ", Data)}]" : $"Array[{Data.Length}]";
|
|
} |