-
Notifications
You must be signed in to change notification settings - Fork 6k
[csharp] Return ICollection<T> instead of List<T> #1964
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
[csharp] Return ICollection<T> instead of List<T> #1964
Conversation
@jimschubert thanks for the PR. Given that it's a breaking (non-backward compatible) change, I would suggest adding a CLI option (e.g. returnICollection) that defaults to false to begin with. |
This change is inline with Microsoft's recommended guidelines for collects (https://msdn.microsoft.com/en-us/library/dn169389(v=vs.110).aspx). Added generator options for csharp to: * useCollection: Deserialize responses into and return Collection<T> * returnICollection: For List<T> or Collection<T>, return ICollection<T> instead of the concrete type As a consequence of useCollection, method imputs will also change to Collection<T>.
696d74a
to
9dc4012
Compare
…csharp_List_to_ICollection
@wing328 I've added two options:
|
@jimschubert thanks for adding the option. I tested with useCollection only and got the following error: But when I tested witih both useCollection and returnICollection set to true, I didn't get the error. |
@wing328 I don't know why that would happen. Commented on the line above which includes the import. I noticed that any time I changed the resources, I had to run |
Forgot to mention that the error I got is in Pet.cs (model.mustache) and I don't see |
Ah. That's weird. I can update the model template tomorrow. I can also rebase. |
Thank you 🍺 |
df95d69
to
b4eed0d
Compare
@wing328 I've added that using directive to model.mustache. Looked like my config was only testing both options. Sorry about that. Couldn't rebase all commits because of the merge from master, but everything on my branch is now up to date. |
@jimschubert no problem bro. I'll give it another try later and merge into master accordingly. |
[csharp] Return ICollection<T> instead of List<T>
This change is inline with Microsoft's recommended guidelines for
collections.
This code is based on the discussion in #1338
As mentioned in the issue, converting method signatures to return
ICollection<T>
rather thanList<T>
should be considered a breaking change.This change also reduces the specific type of input parameters from
List<T>
toICollection<T>
, which is not a breaking change becauseList<T>
implementsICollection<T>
.