public List<Section> GetSections()
{
var allParas = Paragraphs;
var parasInASection = new List<Paragraph>();
var sections = new List<Section>();
foreach (var para in allParas)
{
var sectionInPara = para.Xml.Descendants().FirstOrDefault(s => s.Name.LocalName == "sectPr");
if (sectionInPara == null)
{
parasInASection.Add(para);
}
else
{
parasInASection.Add(para);
var section = new Section(Document, sectionInPara) { SectionParagraphs = parasInASection };
sections.Add(section);
parasInASection = new List<Paragraph>();
}
}
XElement body = mainDoc.Root.Element(XName.Get("body", w.NamespaceName));
XElement baseSectionXml = body.Element(XName.Get("sectPr", w.NamespaceName));
var baseSection = new Section(Document, baseSectionXml) { SectionParagraphs = parasInASection };
sections.Add(baseSection);
return sections;
}