Advertisement
Shimmy

Untitled

Oct 9th, 2014
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.88 KB | None | 0 0
  1. <?xml version="1.0" encoding="utf-16"?>
  2. <ChordType name="C Minor" priority="Important">
  3.   <description>C minor</description>
  4.   <abbreviations>
  5.     <abbr category="General">m</abbr>
  6.     <abbr category="Jazz">-</abbr>
  7.     <abbr category="Full">min</abbr>
  8.   </abbreviations>
  9.   <intervals>
  10.     <interval quality="Perfect" number="Unison" />
  11.     <interval quality="Minor" number="Third" />
  12.     <interval quality="Perfect" number="Fifth" />
  13.   </intervals>
  14. </ChordType>
  15.  
  16.     public void ReadXml(XmlReader reader)
  17.     {
  18.       _Name = reader.GetAttribute("name");
  19.       _Priority = (ChordTypePriority)Enum.Parse(typeof(ChordTypePriority), reader.GetAttribute("priority"));
  20.       if (reader.ReadToFollowing("description"))
  21.         _Description = reader.ReadElementContentAsString();
  22.  
  23.       if (reader.Name != "abbreviations")
  24.         throw new InvalidOperationException("Abbreviations element missing.");
  25.       if (!reader.ReadToDescendant("abbr"))
  26.         throw new InvalidOperationException("At least one abbreviation element is required.");
  27.       var abbreviations = new List<ChordTypeAbbreviation>();
  28.       do
  29.       {
  30.         var abbr = new ChordTypeAbbreviation(
  31.           category: reader.GetAttribute("category"),
  32.           abbreviation: reader.ReadElementContentAsString()
  33.           );
  34.  
  35.         abbreviations.Add(abbr);
  36.       } while (reader.ReadToNextSibling("abbr"));
  37.       _Abbreviations = abbreviations.ToArray();
  38.  
  39.       if (!reader.ReadToFollowing("intervals"))
  40.         //here's where the code fails
  41.         throw new InvalidOperationException("Intervals element missing.");
  42.       var intervals = new List<Interval>();
  43.       do
  44.       {
  45.         var interval = new Interval(reader.GetAttribute("quality"), reader.GetAttribute("number"));
  46.         intervals.Add(interval);
  47.       } while (reader.ReadToNextSibling("interval"));
  48.       _Intervals = intervals.ToArray();
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement