-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Added support for serialization for classes containing IList properties #361
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
Conversation
@haacked this look good to me. Can you verify the indentation? |
One question. Why is this for |
Hmm...good point. Maybe IEnumerable would be a better bet On 2013-09-05, at 10:19 PM, Phil Haack notifications@github.com wrote:
|
@scottschluer think you could change it to support IEnumerable real quick? |
Sure. I submitted this PR a while back so my memory is a little fuzzy on it but I seem to recall there was a problem specific to IList. I'll test it tomorrow morning and if it's a problem that extends to IEnumerable, I'll update the PR. |
@scottschluer nice! |
@@ -146,8 +146,13 @@ public class XmlSerializer : ISerializer | |||
else if (rawValue is IList) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is why it's specific to IList. There was an existing logic branch that my patch modified that operated specifically on IList collections. Changing this to IEnumerable would widen the scope of my patch. Following the logic branching in this section of code, IEnumerable or ICollection would fall down to the "else" statement beneath the one I modified.
I added a unit test locally for IEnumerable and it works as intended. The problem was specific to IList collections as there was a logic branch in the existing code that handled IList differently than other types. |
So maybe we should just remove that branch that handles |
I'd have to look further into it, but removing that branch causes three unit tests to fail:
The last one was the test I added as part of this PR. |
Ok, let's just go with your change for now since you have test coverage and it doesn't break existing tests. :) |
Sounds good. I still feel like there's room for improvement on this logic branch now that I'm looking at it again, but that'd be more of a refactor than a bug fix so I'll let it go for now. :) Thanks for the code review. |
Added support for serialization for classes containing IList properties
Given the following class structure:
RestSharp's XmlSerializer returns the following XML:
Note that the serialization of the "EmailAddress" element ignored the SerializeAs attribute.
Code attached to fix this issue and correctly serialize class names when included as an IList<> property.