Table of Contents

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

T

The element type.

Implements
Inherited Members

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.

Intentionally does not implement IEnumerable<T>. LINQ and FluentAssertions interop is via the Items projection — e.g. violations.Items.Should().HaveCount(2). This omission is deliberate so the type's equality semantics cannot be silently bypassed via sequence-style comparison helpers; see the "EquatableArray<T>" recipe in the API cookbook for rationale.

Constructors

EquatableArray(ImmutableArray<T>)

Initializes a new instance wrapping the provided ImmutableArray<T>.

public EquatableArray(ImmutableArray<T> items)

Parameters

items ImmutableArray<T>

The items to wrap.

Fields

Empty

An empty EquatableArray<T>. A single cached instance per closed generic type, mirroring the Empty field-singleton pattern.

public static readonly EquatableArray<T> Empty

Field Value

EquatableArray<T>

Properties

IsEmpty

Gets a value indicating whether the sequence is empty.

public bool IsEmpty { get; }

Property Value

bool

this[int]

Gets the element at the specified zero-based index.

public T this[int index] { get; }

Parameters

index int

The 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

ImmutableArray<T>

Length

Gets the number of items in the sequence.

public int Length { get; }

Property Value

int

Methods

Create(params T[])

Creates an EquatableArray<T> from the provided items.

public static EquatableArray<T> Create(params T[] items)

Parameters

items T[]

The items.

Returns

EquatableArray<T>

A new EquatableArray<T>.

Exceptions

ArgumentNullException

Thrown when items is null.

Equals(object?)

Indicates whether this instance and a specified object are equal.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with the current instance.

Returns

bool

true if obj and 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

other EquatableArray<T>

An object to compare with this object.

Returns

bool

true if the current object is equal to the other parameter; otherwise, false.

From(IEnumerable<T>)

Creates an EquatableArray<T> from the provided items.

public static EquatableArray<T> From(IEnumerable<T> items)

Parameters

items IEnumerable<T>

The items.

Returns

EquatableArray<T>

A new EquatableArray<T>.

Exceptions

ArgumentNullException

Thrown when items is null.

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

left EquatableArray<T>
right EquatableArray<T>

Returns

bool

implicit operator EquatableArray<T>(ImmutableArray<T>)

Implicit conversion from ImmutableArray<T>.

public static implicit operator EquatableArray<T>(ImmutableArray<T> items)

Parameters

items ImmutableArray<T>

The items.

Returns

EquatableArray<T>

operator !=(EquatableArray<T>, EquatableArray<T>)

Inequality operator.

public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right)

Parameters

left EquatableArray<T>
right EquatableArray<T>

Returns

bool