4
4
5
5
using System . Collections ;
6
6
using System . ComponentModel ;
7
+ using System . Diagnostics ;
8
+ using System . Diagnostics . CodeAnalysis ;
9
+ using System . Linq ;
10
+ using System . Runtime . CompilerServices ;
7
11
using XenoAtom . Collections ;
8
12
9
13
namespace Ultra . Core . Model ;
@@ -12,6 +16,8 @@ namespace Ultra.Core.Model;
12
16
/// A generic list class used to store items of type <typeparamref name="T"/>.
13
17
/// </summary>
14
18
/// <typeparam name="T">The type of items in the list.</typeparam>
19
+ [ DebuggerDisplay ( "Count = {Count}" ) ]
20
+ [ DebuggerTypeProxy ( typeof ( UGenericList < > . DebugListView ) ) ]
15
21
public abstract class UGenericList < T > ( int capacity ) : IEnumerable < T >
16
22
{
17
23
/// <summary>
@@ -26,11 +32,29 @@ protected UGenericList() : this(0)
26
32
{
27
33
}
28
34
35
+ /// <summary>
36
+ /// Gets the number of items in the list.
37
+ /// </summary>
38
+ public int Count => List . Count ;
39
+
40
+ /// <summary>
41
+ /// Gets the item at the specified index.
42
+ /// </summary>
43
+ /// <param name="index">The index of the item to get.</param>
44
+ /// <returns>The item at the specified index</returns>
45
+ public T this [ int index ]
46
+ {
47
+ [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
48
+ get => List [ index ] ;
49
+ }
50
+
29
51
/// <summary>
30
52
/// Gets the items in the list as a span.
31
53
/// </summary>
32
54
public ReadOnlySpan < T > Items => List . AsSpan ( ) ;
33
55
56
+ /// <inheritdoc />
57
+ public override string ToString ( ) => $ "{ GetType ( ) . Name } [{ Count } ]";
34
58
35
59
/// <summary>
36
60
/// Gets an enumerator for the items in the list.
@@ -42,4 +66,19 @@ protected UGenericList() : this(0)
42
66
IEnumerator < T > IEnumerable < T > . GetEnumerator ( ) => List . GetEnumerator ( ) ;
43
67
44
68
IEnumerator IEnumerable . GetEnumerator ( ) => List . GetEnumerator ( ) ;
69
+
70
+ [ ExcludeFromCodeCoverage ]
71
+ private sealed class DebugListView ( UGenericList < T > genericList )
72
+ {
73
+ [ DebuggerBrowsable ( DebuggerBrowsableState . RootHidden ) ]
74
+ public T [ ] Items
75
+ {
76
+ get
77
+ {
78
+ T [ ] array = new T [ genericList . Count ] ;
79
+ genericList . List . CopyTo ( ( Span < T > ) array ) ;
80
+ return array ;
81
+ }
82
+ }
83
+ }
45
84
}
0 commit comments