J2N.Collections: Added AsReadOnly() method to each dictionary and set #100
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #93.
J2N.Collections: Added
AsReadOnly()
method to each dictionary and set to ensure it is unaffected by Micorsoft's extension methods of the same name in net core. This ensures read-only collections of the built-in types will always respect structural equality and structural formatting.There will still be collisions using
.AsReadOnly()
if declaringusing J2N.Collections.Generic.Extensions;
andusing System.Collections.Generic;
. In those cases, the user must call the static method that they prefer explicitly.Our extension method existed prior to Microsoft's. We followed a best practice of putting it into a separate namespace than
J2N.Collections.Generic
so users would have an option to not import theJ2N.Collections.Generic.Extensions
if there were a conflict with another library. It was assumed that Microsoft would declareAsReadOnly()
on each collection (as it is onList<T>
) rather than using an extension method so there would be no conflict. Or at least that they would follow the best practice of not including it directly in theSystem.Collections.Generic
namespace. Unfortunately, they did neither of those things.New APIs: