Skip to content

Commit

Permalink
Rename read-only list field of "ListLike"; ditto "CollectionLike"
Browse files Browse the repository at this point in the history
  • Loading branch information
atifaziz authored Jan 27, 2023
1 parent c8004ac commit 5e2a031
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions MoreLinq/CollectionLike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@ namespace MoreLinq
readonly struct CollectionLike<T>
{
readonly ICollection<T>? _rw;
readonly IReadOnlyCollection<T>? _rx;
readonly IReadOnlyCollection<T>? _ro;

public CollectionLike(ICollection<T> collection)
{
_rw = collection ?? throw new ArgumentNullException(nameof(collection));
_rx = null;
_ro = null;
}

public CollectionLike(IReadOnlyCollection<T> collection)
{
_rw = null;
_rx = collection ?? throw new ArgumentNullException(nameof(collection));
_ro = collection ?? throw new ArgumentNullException(nameof(collection));
}

public int Count => _rw?.Count ?? _rx?.Count ?? 0;
public int Count => _rw?.Count ?? _ro?.Count ?? 0;

public IEnumerator<T> GetEnumerator() =>
_rw?.GetEnumerator() ?? _rx?.GetEnumerator() ?? Enumerable.Empty<T>().GetEnumerator();
_rw?.GetEnumerator() ?? _ro?.GetEnumerator() ?? Enumerable.Empty<T>().GetEnumerator();
}
}
10 changes: 5 additions & 5 deletions MoreLinq/ListLike.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ namespace MoreLinq
readonly struct ListLike<T>
{
readonly IList<T>? _rw;
readonly IReadOnlyList<T>? _rx;
readonly IReadOnlyList<T>? _ro;

public ListLike(IList<T> list)
{
_rw = list ?? throw new ArgumentNullException(nameof(list));
_rx = null;
_ro = null;
}

public ListLike(IReadOnlyList<T> list)
{
_rw = null;
_rx = list ?? throw new ArgumentNullException(nameof(list));
_ro = list ?? throw new ArgumentNullException(nameof(list));
}

public int Count => _rw?.Count ?? _rx?.Count ?? 0;
public int Count => _rw?.Count ?? _ro?.Count ?? 0;

public T this[int index] => _rw is { } rw ? rw[index]
: _rx is { } rx ? rx[index]
: _ro is { } rx ? rx[index]
: throw new ArgumentOutOfRangeException(nameof(index));
}

Expand Down

0 comments on commit 5e2a031

Please sign in to comment.