public class Section { public UInt32 Index { get; set; } public UInt32 Start { get; set; } public UInt32 Size { get; set; } public string Description { get; set; } } public class MyFileType { public UInt32 FileID { get; private set; } public UInt32 Size { get; private set; } public string Description { get; private set; } public ICollection
Sections { get; private set; } public MyFileType(UInt32 fileId, UInt32 size, string description, ICollection
sections) { this.FileID = fileId; this.Size = size; this.Description = description; this.Sections = sections; } private class Helper { public UInt32 FileID { get; set; } public UInt32 Size { get; set; } public string Description { get; set; } public IList
Sections { get; set; } } public static MyFileType Create(UInt32 id) { string filename = @"..\..\Xml\FileSections.xml"; var doc = XDocument.Load(filename); var result = doc.Root.Descendants("File") .Where(i => Convert.ToUInt32(i.Attribute("FileID").Value, 16) == id) .Select(x => new Helper { FileID = Convert.ToUInt32(x.Attribute("FileID").Value, 16), Size = Convert.ToUInt32(x.Attribute("Size").Value, 16), Description = x.Attribute("Description").Value, Sections = x.Elements("Sections").Descendants("Section") .Select(y => new Section { Index = Convert.ToUInt32(y.Attribute("Index").Value, 10), Start = Convert.ToUInt32(y.Attribute("Start").Value, 16), Size = Convert.ToUInt32(y.Attribute("Size").Value, 16), Description = y.Value }).ToList() }).FirstOrDefault(); return new MyFileType(result.FileID, result.Size, result.Description, result.Sections); } } /* // Simple use ... UInt32 id = 2; MyFileType myObject = MyFileType.Create(id); //Debug.WriteLine($"File Description: {myObject.Description}"); //foreach (Section section in myObject.Sections) //{ // Debug.WriteLine($"Section Description: {section.Description}"); //} */