Struct EquatableArray<T>
- Namespace
- Trellis
- Assembly
- Trellis.Core.dll
Wraps an ImmutableArray<T> to provide structural (sequence) equality.
public readonly struct EquatableArray<T> : IEquatable<EquatableArray<T>>
Type Parameters
TThe element type.
- Implements
- Inherited Members
- Extension Methods
Remarks
ImmutableArray<T>'s default equality is reference-based: two distinct arrays with identical contents compare unequal. This wrapper restores sequence equality so collection-bearing records work as expected.
A default-constructed EquatableArray<T> represents an empty (uninitialized) sequence; two default values compare equal.
Constructors
EquatableArray(ImmutableArray<T>)
Initializes a new instance wrapping the provided ImmutableArray<T>.
public EquatableArray(ImmutableArray<T> items)
Parameters
itemsImmutableArray<T>The items to wrap.
Properties
Empty
An empty EquatableArray<T>.
public static EquatableArray<T> Empty { get; }
Property Value
IsEmpty
Gets a value indicating whether the sequence is empty.
public bool IsEmpty { get; }
Property Value
this[int]
Gets the element at the specified zero-based index.
public T this[int index] { get; }
Parameters
indexintThe zero-based index of the element to get.
Property Value
- T
The element at the specified index.
Items
Gets the wrapped items. Never returns a default-uninitialized array; an empty array is returned in that case.
public ImmutableArray<T> Items { get; }
Property Value
Length
Gets the number of items in the sequence.
public int Length { get; }
Property Value
Methods
Create(params T[])
Creates an EquatableArray<T> from the provided items.
public static EquatableArray<T> Create(params T[] items)
Parameters
itemsT[]The items.
Returns
- EquatableArray<T>
A new EquatableArray<T>.
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
Equals(EquatableArray<T>)
Indicates whether the current object is equal to another object of the same type.
public bool Equals(EquatableArray<T> other)
Parameters
otherEquatableArray<T>An object to compare with this object.
Returns
From(IEnumerable<T>)
Creates an EquatableArray<T> from the provided items.
public static EquatableArray<T> From(IEnumerable<T> items)
Parameters
itemsIEnumerable<T>The items.
Returns
- EquatableArray<T>
A new EquatableArray<T>.
GetEnumerator()
Returns an enumerator that iterates through the items.
public ImmutableArray<T>.Enumerator GetEnumerator()
Returns
- ImmutableArray<T>.Enumerator
An enumerator for the items.
GetHashCode()
Returns the hash code for this instance.
public override int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
Operators
operator ==(EquatableArray<T>, EquatableArray<T>)
Equality operator.
public static bool operator ==(EquatableArray<T> left, EquatableArray<T> right)
Parameters
leftEquatableArray<T>rightEquatableArray<T>
Returns
implicit operator EquatableArray<T>(ImmutableArray<T>)
Implicit conversion from ImmutableArray<T>.
public static implicit operator EquatableArray<T>(ImmutableArray<T> items)
Parameters
itemsImmutableArray<T>The items.
Returns
operator !=(EquatableArray<T>, EquatableArray<T>)
Inequality operator.
public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right)
Parameters
leftEquatableArray<T>rightEquatableArray<T>