Hello, I have no firm idea how to word this question, so forgive me if I don't use the correct terminology.
I have a System.Xml.Linq.XElement el
which contains an xml document. I want to query a part of the XElement and add user objects (Upload
) to a generic list (UploadList
held in a page property) like so:
this.UploadsList.Add((from el1 in el.Descendants("Uploads")
select new Upload
{
Comments = el1.Element("Comments") != null ? el1.Element("Comments").Value : ""
,
***ConsentForImageUse.Text=el1.Element("SomeNode") != null ? el1.Element("SomeNode").Value : ""***
,
DateImageProduced = el1.Element("DateImageProduced").Value != "" ? DateTime.Parse(el1.Element("DateImageProduced").Value) : DateTime.MinValue
,
ImageTakenBy = el1.Element("ImageTakenBy") != null ? el1.Element("ImageTakenBy").Value : ""
}).First<Upload>());
The compiler complains about the bit with the asterisks.
My Upload object has a property ConsentForImageUse
which is itself a class with a couple of properties.
The error is Invalid initialiser member declarator. Does anyone know if I can create 'complex' objects using Linq like this like this?