Я работаю над веб-приложением Silverlight, которое работает с XML подобно:
<?xml version="1.0" encoding="UTF-8" ?>
<ProjectList>
<Type>web</Type>
<Project>
<Id>1</Id>
<Name>test web project</Name>
<Description>test web project</Description>
<ScreenshotList>
<Screenshot>
<Path>screen1.jpg</Path>
<Description>This a description of screen 1</Description>
</Screenshot>
<Screenshot>
<Path>screen2.jpg</Path>
<Description>This a description of screen 2</Description>
</Screenshot>
<Thumb>noThumb.jpg</Thumb>
</ScreenshotList>
</Project>
</ProjectList>
Я хотел бы создать новый объект для каждого элемента Project в XML. У меня есть класс с именем project, который содержит поля для id, name, description, thumb и список для всех скриншотов.
Мой текущий код LINQ выглядит так:
var projects = from project in xDoc.Root.Elements("Project")
select new Project(
Int32.Parse(project.Element("Id").Value, CultureInfo.InvariantCulture),
project.Element("Name").Value,
project.Element("Description").Value,
project.Element("ScreenshotList").Element("Thumb").Value
);
Можно ли в любом случае легко получить скриншоты и добавить их в список в экземпляре Project в рамках этого одного запроса?
РЕДАКТИРОВАТЬ - Добавление конструктора проекта
public Project(int id, string name, string description, string thumbPath)
{
this.id = id;
this.name = name;
this.description = description;
this.thumbPath = thumbPath;
}