Example #1
0
 /// <summary>
 /// 返回全部的歌曲
 /// </summary>
 /// <returns></returns>
 public List<Music> GetMusics()
 {
     List<Music> AllMusic = new List<Music>();
     //加载文件
     XElement Xe = XElement.Load(this.XmlFilePath);
     //读取列表
     IEnumerable<XElement> Elements = from Musics in Xe.Elements("Music") select Musics;
     foreach (XElement Element in Elements)
     {
         MusicType Type = GetTypeByValue(Element.Element("Type").Value);
         Music Music = new Music(Element.Element("Title").Value, 
                                 Element.Element("Url").Value,
                                 Convert.ToInt32(Element.Element("Like").Value), 
                                 Convert.ToInt32(Element.Element("Listen").Value),
                                 Type);
         AllMusic.Add(Music);
     }
     return AllMusic;
 }
Example #2
0
 /// <summary>
 /// 返回指定歌曲名称的Music
 /// </summary>
 /// <returns></returns>
 public Music GetMusic(string Title)
 {
     Music m = null; ;
     //加载文件
     XElement Xe = XElement.Load(this.XmlFilePath);
     //读取列表
     IEnumerable<XElement> Elements = from Musics in Xe.Elements("Music")  where Musics.Element("Title").Value==Title select Musics;                        
     foreach (XElement Element in Elements)
     {
         m = new Music(Element.Element("Title").Value, 
             Element.Element("Url").Value,
             Convert.ToInt32(Element.Element("Like").Value),
             Convert.ToInt32(Element.Element("Listen").Value),
             GetTypeByValue(Element.Element("Type").Value));
     }
     return m;
 }