-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTinyArray.cs
More file actions
59 lines (47 loc) · 1.89 KB
/
TinyArray.cs
File metadata and controls
59 lines (47 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections;
using System.Collections.Generic;
namespace Tiny
{
public class TinyArray : TinyToken, IList<TinyToken>
{
private readonly List<TinyToken> tokens = new List<TinyToken>();
public override bool IsInline => false;
public override bool IsEmpty => tokens.Count == 0;
public override TinyTokenType Type => TinyTokenType.Array;
public TinyToken this[int index]
{
get => tokens[index];
set => tokens[index] = value;
}
public TinyArray()
{
}
public TinyArray(IEnumerable values)
{
foreach (var value in values)
Add(ToToken(value));
}
public int Count => tokens.Count;
public bool IsReadOnly => false;
public void Add(TinyToken item) => tokens.Add(item);
public void Clear() => tokens.Clear();
public bool Contains(TinyToken item) => tokens.Contains(item);
public void CopyTo(TinyToken[] array, int arrayIndex) => tokens.CopyTo(array, arrayIndex);
public int IndexOf(TinyToken item) => tokens.IndexOf(item);
public void Insert(int index, TinyToken item) => tokens.Insert(index, item);
public bool Remove(TinyToken item) => tokens.Remove(item);
public void RemoveAt(int index) => tokens.RemoveAt(index);
public IEnumerator<TinyToken> GetEnumerator() => tokens.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => tokens.GetEnumerator();
public override T Value<T>(object key)
{
if (key == null)
return (T)(object)this;
if (key is int index)
return this[index].Value<T>();
throw new ArgumentException($"Key must be an integer, was {key}", "key");
}
public override string ToString() => string.Join(", ", tokens);
}
}