Struct SingleOrArray<T>
- Holds either a single T or many T values without boxing.
- Avoids allocations for the single case (no implicit single-to-array creation).
- Implements IReadOnlyList for predictable access.
Assembly: Glitch9.IO.dll
Syntax
public readonly struct SingleOrArray<T> : IReadOnlyList<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable
Type Parameters
Constructors
|
Edit this page
View Source
SingleOrArray(T)
Declaration
public SingleOrArray(T single)
Parameters
| Type |
Name |
Description |
| T |
single |
|
|
Edit this page
View Source
SingleOrArray(T[])
Declaration
public SingleOrArray(T[] array)
Parameters
| Type |
Name |
Description |
| T[] |
array |
|
Properties
|
Edit this page
View Source
Array
Declaration
public T[] Array { get; }
Property Value
|
Edit this page
View Source
Count
Declaration
public int Count { get; }
Property Value
|
Edit this page
View Source
IsArray
Declaration
public bool IsArray { get; }
Property Value
|
Edit this page
View Source
IsNone
Declaration
public bool IsNone { get; }
Property Value
|
Edit this page
View Source
IsSingle
Declaration
public bool IsSingle { get; }
Property Value
|
Edit this page
View Source
this[int]
Declaration
public T this[int index] { get; }
Parameters
| Type |
Name |
Description |
| int |
index |
|
Property Value
|
Edit this page
View Source
Single
Declaration
Property Value
Methods
|
Edit this page
View Source
Cast<T1, T2>(SingleOrArray<T1>)
Declaration
public static SingleOrArray<T2> Cast<T1, T2>(SingleOrArray<T1> source) where T1 : T2
Parameters
Returns
Type Parameters
|
Edit this page
View Source
CopyAndAdd(T)
Declaration
public SingleOrArray<T> CopyAndAdd(T item)
Parameters
| Type |
Name |
Description |
| T |
item |
|
Returns
|
Edit this page
View Source
CopyTo(Span<T>)
- Copies into destination and returns written count.
- Zero allocation.
Declaration
public int CopyTo(Span<T> destination)
Parameters
| Type |
Name |
Description |
| Span<T> |
destination |
|
Returns
|
Edit this page
View Source
GetEnumerator()
Declaration
public SingleOrArray<T>.Enumerator GetEnumerator()
Returns
|
Edit this page
View Source
ToArray()
- Allocates only when single is requested as an array.
- Prefer IReadOnlyList/foreach/CopyTo for zero alloc.
Declaration
Returns
|
Edit this page
View Source
ToString()
Declaration
public override string ToString()
Returns
Overrides
Operators
|
Edit this page
View Source
implicit operator SingleOrArray<T>(T)
Declaration
public static implicit operator SingleOrArray<T>(T value)
Parameters
| Type |
Name |
Description |
| T |
value |
|
Returns
|
Edit this page
View Source
implicit operator SingleOrArray<T>(T[])
Declaration
public static implicit operator SingleOrArray<T>(T[] values)
Parameters
| Type |
Name |
Description |
| T[] |
values |
|
Returns
Implements
Extension Methods