Can someone explain the LINQ to XML below? Also, what is the correct way to check if the method returned a List with Data? Do you just check if the List is empty.
Code:
public List<Listing> GetList()
{
if (File.Exists(this.xmlFilePath))
{
XDocument doc = XDocument.Load(this.xmlFilePath);
var listings = from row in doc.Root.Elements("listing")
select new Listing
{
A = (string)row.Element("A"),
B = (string)row.Element("B"),
C = (string)row.Element("C"),
D = (string)row.Element("D"),
E = (string)row.Element("E")
};
return listings.ToList();
}
else
{
return new List<Listing>();
}
}
XML:
<Listings>
<listing>
<a>A</a>
<b>B</b>
<c>C</c>
<d>D</d>
<e>E</e>
</listing>
<listing>
<a>F</a>
<b>G</b>
<c>C</c>
<d>H</d>
<e>I</e>
</listing>
</Listings>