Reputation: 199
I have class TestCase which contains list of results:
[XmlRoot("TestCase")]
public class TestCase
{
[XmlAttribute("Name")]
public string Name { get; set; }
[XmlElement("Results", typeof(List<TestCaseResult>))]
public List<TestCaseResult> Results
{
get
{
return results.OrderByDescending(x => x.Time).ToList();
}
set
{
results = value;
}
}
TestCaseResult looks like this:
[XmlRoot("TestCaseResult")]
public class TestCaseResult
{
[XmlElement("HtmlPath")]
public string HtmlPath { get; set; }
[XmlElement("Status")]
public string Status { get; set; }
[XmlElement("FailedCommand")]
public string FailedCommand { get; set; }
[XmlElement("Time")]
public DateTime Time { get; set; }
what I do, is I collect testcases into List and then I'm serializing it. I serialize whole list, right after that I deserialize it and List is empty. but results are stored in xml correctly. what am I doing wrong?
edit: added setter to TestCase.Results, but it did not help, problem is still there. Results are deserialized empty.
Upvotes: 0
Views: 47
Reputation: 199
Looks like problem was with the actual getter, which returned sorted list.
probably when deserializing, framework asks for List and then fills it, when I ordered the list I actually created new one, so the original was never filled.
Upvotes: 0
Reputation: 3161
If you mean Results
is empty than you need setter for this property
[XmlElement("Results", typeof(List<TestCaseResult>))]
public List<TestCaseResult> Results
{
get
{
return results.OrderByDescending(x => x.Time).ToList();
}
set
{
results = value;
}
}
Upvotes: 1