question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Virtualize component's Items property should be IReadOnlyCollection

See original GitHub issue

Background and Motivation

The <Virtualize TItem="T"> component should allow users to pass a IReadOnlyCollection<T> to the Items property/parameter instead of requiring an ICollection.

There should be no need for the Virtualize component to change the collection passed to it, so changing the parameter to an IReadOnlyCollection<T> should be straight forward, that allows users to pass a wider range of collection types (including custom ones) to the Virtualize component.

Proposed API change to Virtualize.cs

/// <summary>
/// Gets or sets the fixed item source.
/// </summary>
[Parameter]
-public ICollection<TItem>? Items { get; set; }
+public IReadOnlyCollection<TItem>? Items { get; set; }

Usage Examples

N/A

Alternative Designs

N/A

Risks

Since ICollection does not implements IReadOnlyCollection this is a breaking change if users are using custom collection types that implements ICollection but not IReadOnlyCollection. Changing that for the end user will be trivial though.

Updated: changed to reflect this is a breaking change. Op

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
javiercncommented, Feb 16, 2022

@egil unfortunately we don’t do breaking changes like this unless we have a really good justification for them.

It’s unfortunate that we chose ICollection instead of IReadOnlyCollection but we prefer to avoid breaking existing customers (no matter how few they might be) over improving the correctness of the interface.

With changes like these, is not just about breaking an existing app that would need to recompile to work, its potentially breaking existing libraries that build on top and that would need to be updated.

That, we think is a much bigger risk compared to the benefit of being more “correct/explicit” about the type used.

I understand that this might not align with your preferences, but at least I hope the arguments explain our rationale.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - IEnumerable vs IReadonlyCollection vs ...
When an IEnumerable<T> is returned to the caller, they must consider the possibility that the returned object is a "lazy stream", e.g. a ......
Read more >
The New Read-Only Collections in .NET 4.5
The IReadOnlyCollection is the most basic read-only collection interface and provides a Count property on top of its inherent IEnumerable ...
Read more >
ASP.NET Core Razor component virtualization
Use the Virtualize component (reference source) when: Rendering a set of data items in a loop. Most of the items aren't visible due...
Read more >
Exposing Private Collection Properties to Entity Framework
Ideally, collections should be exposed as either read-only collections or even simply as enumerations (IEnumerable ), with care taken to ensure ...
Read more >
How to work with read-only collections in C# | InfoWorld
Collections enable you to allocate memory dynamically to store elements and then retrieve them using a key or index as needed.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found