コード例 #1
0
ファイル: Program.cs プロジェクト: hatahet/antobot
 private static IEnumerable<XElement> getSwearStatsXml(SwearingStats sstats)
 {
     return new XElement[]
     {
         new XElement("totalwords", sstats.totalWords),
         new XElement("swearwords", sstats.swearWords),
         new XElement("popularity",
             sstats.popularity.Select(x => new XElement(x.Key, x.Value)))
     };
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: hatahet/antobot
        private static SwearingStats getSwearStatsFromXml(XElement[] elements)
        {
            XElement twords = elements[0];
            XElement swords = elements[1];
            XElement pop = elements[2];

            int twordsI = int.Parse(twords.Value);
            int swordsI = int.Parse(swords.Value);
            Dictionary<string, int> popularity =
                pop.Elements().ToDictionary(x => x.Name.LocalName, x => int.Parse(x.Value));

            SwearingStats sstats = new SwearingStats();
            sstats.popularity = popularity;
            sstats.swearWords = swordsI;
            sstats.totalWords = twordsI;

            return sstats;
        }