Cysharp / Cysharp/ObservableCollections
SynchronizedViewList throws on ToList() / when used as IEnumerable
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 1k
- Forks
- 73
- Avg merge
- 5d 4h
- Merged PRs (30d)
- 2
Description
When creating a ISynchronizedViewList (to have a simple list instead of mapping pairs) to ToList() method throws an exception on .ToList().
This only happens when there's actual items in the list.
This forces us to use the underlying ListView or its Filtered member with a Select() to actually copy or iterate the ViewList.
This makes the ViewList a very unreliable IEnumerable, prompting our team to actually never use it.
var sourceList = new ObservableList<int>();
var listView = sourceList.CreateView(x => x);
//Fill the list
sourceList.Add(42);
//This works
var listViewContents = listView.ToList();
var listViewContentsViaFiltered = listView.Filtered.Select(tuple => tuple.View).ToList();
//This throws
var listViewContentsViaViewList = listView.ToViewList().ToList();
Also see fiddle
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the ObservableList, CreateView, and ToViewList().ToList() example from the report, then trace the ToViewList() IEnumerable path for a populated view. Done means enumerating a populated ISynchronizedViewList and converting it with ToList() no longer throws, while the existing Filtered.Select path remains consistent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100