Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace ToReadOnlyCollection with AsReadOnlyList #5

Merged
merged 1 commit into from
Sep 2, 2017

Conversation

bgrainger
Copy link
Member

The semantics of ToReadOnlyCollection were confusing to many developers, as it doesn't guarantee that the underlying collection can't be mutated. (It was an "antipattern" to use it in a constructor and store the returned value in a field.)

The new AsReadOnlyList method provides the same efficiency, with a name that implies it's just a view, not a conversion.

Most callers of ToReadOnlyCollection should just switch to AsReadOnlyList; constructors should explicitly call .ToList().AsReadOnly() (or .ToList().AsReadOnlyList()) to make a private copy of a collection supplied via a constructor argument.

The semantics of ToReadOnlyCollection were confusing to many developers, as it doesn't guarantee that the underlying collection can't be mutated. (It was an "antipattern" to use it in a constructor and store the returned value in a field.)

The new AsReadOnlyList method provides the same efficiency, with a name that implies it's just a view, not a conversion.
@bgrainger bgrainger merged commit ba736a2 into Faithlife:master Sep 2, 2017
@bgrainger bgrainger deleted the asreadonlylist branch September 2, 2017 19:45
ddunkin pushed a commit that referenced this pull request Apr 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants