EquatableArray
A wrapper around an array that implements IEquatable<T> for value-based equality comparison.
internal readonly struct EquatableArray<T> : System.IEquatable<EquatableArray<T>>, System.Collections.Generic.IEnumerable<T> where T : System.IEquatable<T>Examples
Section titled “Examples”The following example uses EquatableArray in a model passed through an incremental generator pipeline so that changes are detected by value instead of by reference.
using System.Collections.Immutable;using Hertzole.SourceGen;
internal readonly record struct TypeModel(string Name, EquatableArray<string> Members);
internal static class ModelFactory{ public static TypeModel Create(string name, ImmutableArray<string> members) { // Implicitly converts ImmutableArray<T> to EquatableArray<T>. return new TypeModel(name, members); }
public static bool HasSameMembers(TypeModel left, TypeModel right) { // Compares the contents of the arrays, not the array references. return left.Members.Equals(right.Members); }}Constructors
Section titled “Constructors”EquatableArray(T[])
Section titled “EquatableArray(T[])”Creates a new EquatableArray<T> from the specified array. The array is copied.
public EquatableArray(T[] array);The array to wrap.
EquatableArray(ImmutableArray<T>)
Section titled “EquatableArray(ImmutableArray<T>)”Creates a new EquatableArray<T> from the specified immutable array.
public EquatableArray(ImmutableArray<T> array);The immutable array to wrap.
Properties
Section titled “Properties”IsEmpty
Section titled “IsEmpty”public bool IsEmpty { get; }Length
Section titled “Length”public int Length { get; }Item[]
Section titled “Item[]”public ref readonly T this[int index] { get; }Methods
Section titled “Methods”AsImmutableArray()
Section titled “AsImmutableArray()”Converts this EquatableArray<T> to an ImmutableArray<T>.
public ImmutableArray<T> AsImmutableArray();Returns
Section titled “Returns”An ImmutableArray<T> containing the elements.
AsSpan()
Section titled “AsSpan()”Returns a read-only span over the elements of this EquatableArray<T>.
public ReadOnlySpan<T> AsSpan();Returns
Section titled “Returns”A read-only span over the elements.
Equals(EquatableArray<T>)
Section titled “Equals(EquatableArray<T>)”Determines whether this instance is equal to another EquatableArray<T>.
public bool Equals(EquatableArray<T> other);The other instance to compare.
Returns
Section titled “Returns”true if this instance is equal to other; otherwise false.
Equals(object?)
Section titled “Equals(object?)”Determines whether this instance is equal to the specified object.
public override bool Equals(object? other);The object to compare.
Returns
Section titled “Returns”true if this instance is equal to other; otherwise false.
GetEnumerator()
Section titled “GetEnumerator()”Returns an enumerator that iterates through the elements.
public ImmutableArray<T>.Enumerator GetEnumerator();Returns
Section titled “Returns”An enumerator that iterates through the elements.
GetHashCode()
Section titled “GetHashCode()”Returns the hash code for this instance.
public override int GetHashCode();Returns
Section titled “Returns”The hash code for this instance.
Operators
Section titled “Operators”Implicit (ImmutableArray<T> to EquatableArray<T>)
Section titled “Implicit (ImmutableArray<T> to EquatableArray<T>)”Implicitly converts an ImmutableArray<T> to an EquatableArray<T>.
public static implicit operator EquatableArray<T>(ImmutableArray<T> array);Returns
Section titled “Returns”The converted EquatableArray<T>.
Implicit (EquatableArray<T> to ImmutableArray<T>)
Section titled “Implicit (EquatableArray<T> to ImmutableArray<T>)”Implicitly converts an EquatableArray<T> to an ImmutableArray<T>.
public static implicit operator ImmutableArray<T>(EquatableArray<T> array);Returns
Section titled “Returns”The converted ImmutableArray<T>.
Equality(EquatableArray<T>, EquatableArray<T>)
Section titled “Equality(EquatableArray<T>, EquatableArray<T>)”Determines whether two EquatableArray<T> instances are equal.
public static bool operator ==(EquatableArray<T> left, EquatableArray<T> right);Returns
Section titled “Returns”true if left is equal to right; otherwise false.
Inequality(EquatableArray<T>, EquatableArray<T>)
Section titled “Inequality(EquatableArray<T>, EquatableArray<T>)”Determines whether two EquatableArray<T> instances are not equal.
public static bool operator !=(EquatableArray<T> left, EquatableArray<T> right);Returns
Section titled “Returns”true if left is not equal to right; otherwise false.