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

Added AsReadOnly extension methods for IDictionary<T, U> and IList<T> #61172

Merged

Conversation

Mrxx99
Copy link
Contributor

@Mrxx99 Mrxx99 commented Nov 3, 2021

Resolves #33033

I have made the code changes, but I have some problems:
- Using the ReadOnlyDictionary<T, U> in the CollectionExtensions class in System.Collections.csproj is not possible. It can't find the reference and I don't know what to do here. Adding the System.ObjectModel.csproj to the System.Collections.sln and adding a project reference from that project to System.Collections.csproj did not work.
- Adding the ref project for System.ObjectModel to the ref project for System.Collections complains about a cycle because System.ObjectModel already references System.Collections. With that is it even possible to add the extension method for ReadOnlyDictionary to CollectionExtensions in System.Collections? (ReadOnlyCollection is no problem because it is inside the System.Runtime.dll)
- Where should XML-Doc comments be added? The other methods in CollectionExtensions have none but they show up in intellisense.

Can someone please help me here?

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Nov 3, 2021
@dotnet-issue-labeler
Copy link

Note regarding the new-api-needs-documentation label:

This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change.

@ghost
Copy link

ghost commented Nov 3, 2021

Tagging subscribers to this area: @dotnet/area-system-collections
See info in area-owners.md if you want to be subscribed.

Issue Details

Resolves #33033

I have made the code changes, but I have some problems:

  • Using the ReadOnlyDictionary<T, U> in the CollectionExtensions class in System.Collections.csproj is not possible. It can't find the reference and I don't know what to do here. Adding the System.ObjectModel.csproj to the System.Collections.sln and adding a project reference from that project to System.Collections.csproj did not work.
  • Adding the ref project for System.ObjectModel to the ref project for System.Collections complains about a cycle because System.ObjectModel already references System.Collections. With that is it even possible to add the extension method for ReadOnlyDictionary to CollectionExtensions in System.Collections? (ReadOnlyCollection is no problem because it is inside the System.Runtime.dll)
  • Where should XML-Doc comments be added? The other methods in CollectionExtensions have none but they show up in intellisense.

Can someone please help me here?

Author: Mrxx99
Assignees: -
Labels:

area-System.Collections, new-api-needs-documentation, community-contribution

Milestone: -

@Mrxx99 Mrxx99 changed the title [Help wanted] added AsReadOnly extension methods for IDictionary<T, U> and IList<T> Sdded AsReadOnly extension methods for IDictionary<T, U> and IList<T> Nov 4, 2021
@Mrxx99 Mrxx99 changed the title Sdded AsReadOnly extension methods for IDictionary<T, U> and IList<T> Added AsReadOnly extension methods for IDictionary<T, U> and IList<T> Nov 4, 2021
@eiriktsarpalis
Copy link
Member

Where should XML-Doc comments be added? The other methods in CollectionExtensions have none but they show up in intellisense.

@Mrxx99 please go ahead and add triple-slash documentation directly on the implementation method. We will sync this up the dotnet-api-docs repo at a later stage.

@eiriktsarpalis eiriktsarpalis self-assigned this Nov 15, 2021
@Mrxx99
Copy link
Contributor Author

Mrxx99 commented Nov 15, 2021

@eiriktsarpalis I added the documentation comments. I looked at the documentation comments for the List.AsReadOnly() method and the type and constructor documentation for ReadOnlyCollection and ReadOnlyDictionary<TKey, TValue> and combined the information from them. I hope they are okay.

List.AsReadOnly()
//
// Summary:
//     Returns a read-only System.Collections.ObjectModel.ReadOnlyCollection\`1 wrapper
//     for the current collection.
//
// Returns:
//     An object that acts as a read-only wrapper around the current System.Collections.Generic.List`1.
ReadOnlyCollection
//
// Summary:
//     Provides the base class for a generic read-only collection.
//
// Type parameters:
//   T:
//     The type of elements in the collection.
//
// Summary:
//     Initializes a new instance of the System.Collections.ObjectModel.ReadOnlyCollection`1
//     class that is a read-only wrapper around the specified list.
//
// Parameters:
//   list:
//     The list to wrap.
//
// Exceptions:
//   T:System.ArgumentNullException:
//     list is null.
ReadOnlyDictionary
//
// Summary:
//     Represents a read-only, generic collection of key/value pairs.
//
// Type parameters:
//   TKey:
//     The type of keys in the dictionary.
//
//   TValue:
//     The type of values in the dictionary.
//
// Summary:
//     Initializes a new instance of the System.Collections.ObjectModel.ReadOnlyDictionary`2
//     class that is a wrapper around the specified dictionary.
//
// Parameters:
//   dictionary:
//     The dictionary to wrap.
//
// Exceptions:
//   T:System.ArgumentNullException:
//     dictionary is null.

@Mrxx99 Mrxx99 marked this pull request as ready for review November 15, 2021 16:34
@eiriktsarpalis eiriktsarpalis force-pushed the feature/IListAndIDictionaryAsReadOnlyExtension branch from cedde23 to d88abd7 Compare November 22, 2021 15:21
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Collections community-contribution Indicates that the PR has been added by a community member new-api-needs-documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add extension method AsReadOnly() for IDictionary<TKey, TValue>
4 participants