Invalid initializer member declaration error reading out XML



I have 2 classes:



public class Person
{
public PersonDetail personDetails { get; set; }
}

public class PersonDetail
{
public int Id { get; set; }
public string Name { get; set; }
public string Function { get; set; }
}


When I want to read out the persons from the xml file I get this error "Invalid initializer member declaration":



foreach (var item in xmlFile.Descendants("person"))
{
if (item.Element("id") != null)
{
testList.Add(new Person()
{
**personDetails.Id** = item.Element("id").Value,
**personDetails.Name** = item.Element("name").Value,
**personDetails.Function** = item.Element("function").Value
});
}
}


I can't reach "id", "name" and "function" via "personDetails". Any ideas?


No comments:

Post a Comment