Home > Generics, LINQ > Reading XML into Generic List of Classes

Reading XML into Generic List of Classes


Public Function GetCustomers() As List(Of Customer)
Dim data As XDocument = XDocument.Load("c:\customers\customers.xml"))

Return (From c In data.Descendants("Customer")
Order By c.Attribute("Surname")
New Customer() With { _
Key .ID = Convert.ToInt32(c.Attribute("ID").Value), _
Key .Forename = c.Element("Forename").Value, _
Key .Surname = c.Element("Surname").Value, _
Key .DOB = c.Element("DOB").Value, _
Key .Location = c.Element("Location").Value _
}).ToList()
End Function

 

Advertisements
Categories: Generics, LINQ Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: