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

Readonly response models #658

Merged
merged 14 commits into from
Jan 5, 2015
Merged

Readonly response models #658

merged 14 commits into from
Jan 5, 2015

Conversation

haacked
Copy link
Contributor

@haacked haacked commented Jan 2, 2015

This makes our response models readonly. I made the setters protected instead of private to provide flexibility for others such as inheritors, testers, etc.. Also, it gets rid of that warning that the setter is never used. Let me know what you think.

Fixes #650


/// <summary>
/// The <seealso cref="User"/> that created the deployment.
/// </summary>
public User Creator { get; set; }
public User Creator { get; protected set; }

/// <summary>
/// JSON payload with extra information about the deployment.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these be removed now? There are about 12 of them...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about it, shouldn't collection properties be initialized in the constructors and have private setters? I assume SimpleJson supports it since it supports protected setters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't initialize them in the ctors for these types because they'll just get replaced when SimpleJson deserializes the json into an object. It uses the private setters to set the collection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a follow-up. For "request models" what you described is exactly correct. The ctor should instantiate the collection and the setter should be private. I made that change. Let me know if you find any cases I missed.

@khellang
Copy link
Contributor

khellang commented Jan 2, 2015

Also, does 1e1039f mean that all List<T> properties etc. can be converted to IReadOnlyList<T>?

@haacked
Copy link
Contributor Author

haacked commented Jan 2, 2015

Quite possibly! I'll test it out.

@haacked
Copy link
Contributor Author

haacked commented Jan 2, 2015

Also, it looks like there were some new model types I missed when I merged master in.

@haacked
Copy link
Contributor Author

haacked commented Jan 2, 2015

SimpleJson doesn't support readonly dictionaries. And yet another yak appears!

@haacked
Copy link
Contributor Author

haacked commented Jan 2, 2015

Ok, I created a PR to simple-json. In the meanwhile, I'll just edit our copy directly.

@haacked
Copy link
Contributor Author

haacked commented Jan 3, 2015

Ok, I think this is ready. Would love some 👀 on it. Thanks for the excellent review so far @khellang.

@shiftkey shiftkey self-assigned this Jan 3, 2015
haacked added 13 commits January 3, 2015 20:21
It's bothered me that our response models are mutable. They really
shouldn't be. I made the properties have a protected setter instead of
private to provide flexibility for others who might be deriving from
these classes or testing them.

Fixes #650
This test tried to serialize a response type. We only DEserialize
those.
Looks like we're not keeping the other platform unit test projects
up to date with the main one.
I need to submit a PR for this upstream as well.
Also added a test for it.
Found a bug in which we were using Name when we should be using Login.
They are now readonly and implement a generic base class.
@haacked haacked force-pushed the haacked/readonly-response-models branch from cb33852 to 60373ea Compare January 4, 2015 04:23
public SignatureResponse Author { get; protected set; }
public SignatureResponse Committer { get; protected set; }
public GitReference Tree { get; protected set; }
public IEnumerable<GitReference> Parents { get; protected set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IReadOnlyList<GitReference>?

@khellang
Copy link
Contributor

khellang commented Jan 4, 2015

Changed test in khellang@619a282 to verify handling of readonly collections, and it works beatifully 😁 Maybe there should be a convention test that verifies that collections are of the right type? Is there a reason for sometimes using IReadOnlyCollection<T> over IReadOnlyList<T>?

@haacked
Copy link
Contributor Author

haacked commented Jan 4, 2015

Is there a reason for sometimes using IReadOnlyCollection over IReadOnlyList

Good question. I don't see any benefit to using collection over list here. List provides an indexer which can be handy.

@haacked
Copy link
Contributor Author

haacked commented Jan 4, 2015

🍧

@shiftkey
Copy link
Member

shiftkey commented Jan 4, 2015

Maybe there should be a convention test that verifies that collections are of the right type?

❤️❤️❤️❤️❤️ #660

@haacked haacked force-pushed the haacked/readonly-response-models branch from 5ec1d51 to 1dd42ec Compare January 4, 2015 22:28
@haacked
Copy link
Contributor Author

haacked commented Jan 4, 2015

🍍

@shiftkey
Copy link
Member

shiftkey commented Jan 5, 2015

shiftkey added a commit that referenced this pull request Jan 5, 2015
@shiftkey shiftkey merged commit f8e16a3 into master Jan 5, 2015
@shiftkey shiftkey deleted the haacked/readonly-response-models branch January 5, 2015 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Response models should be readonly
3 participants