I am getting compiler error: 'System.Collections.Generic.List' to 'System.Xml.Linq.XName'.
I was orgininally getting an 'XAttribute' does not contain a definition for 'Trim' and no accessible extension method 'Trim' ...etc.' but I think I figured it out that my quotes were in the wrong place.
What am I doing wrong?
public static List<Phrase> LoadPhrasesFromXMLFile(string file)
{
try
{
XDocument xdocument = XDocument.Load(file);
char[] trim = new char[3] { '\'', '"', ' ' };
return xdocument.Descendants("Phrase").Select((Func<XElement, Phrase>)(x => new Phrase()
{
eventname = (string)x.Attribute("Event".Trim(trim)),
priority = int.Parse((string)x.Attribute("Priority".Trim(trim))),
words = x.Descendants("Word").Select((Func<XElement, Word>)(y =>
{
Word word1 = new Word
{
preferred_text = (string)y.Attribute("Primaries".Trim(trim).ToLower())
};
List<string> stringList = (string)y.Attribute("Secondaries") == null || string.IsNullOrWhiteSpace((string)y.Attribute("Secondaries"))
? new List<string>()
Fails at this line:
: (List<string>)(IEnumerable<string>)(string)y.Attribute("Secondaries".Trim(trim).Replace(" ", "").ToLower().Split(',').ToList());
Cont code:
Word word2 = word1;
word2.Ssecondaries = stringList;
return word1;
})).ToList<Word>()
})).ToList<Phrase>();
}
Error catching:
catch (Exception ex)
{
Sup.Logger("Encountered an exception reading '" + file + "'. It was: " + ex.ToString(), false, true);
}
return (List<Phrase>)null;
}