Пример #1
0
 public void MenuGroup_FromXML_ValidObject()
 {
     var mi = new MenuGroup();
       string xmlIn = "<menu_group uid=\"1\" name=\"myname\">\r\n  <menu_group_description>desc</menu_group_description>\r\n  <menu_items>\r\n    <menu_item uid=\"1\">\r\n      <menu_item_name>item1</menu_item_name>\r\n      <menu_item_description>desc1</menu_item_description>\r\n      <menu_item_price>0</menu_item_price>\r\n    </menu_item>\r\n    <menu_item uid=\"2\">\r\n      <menu_item_name>item2</menu_item_name>\r\n      <menu_item_description>desc2</menu_item_description>\r\n      <menu_item_price>0</menu_item_price>\r\n    </menu_item>\r\n  </menu_items>\r\n</menu_group>";
       XElement xmlElem = XElement.Load(new StringReader(xmlIn));
       mi.FromXML(xmlElem);
       Assert.AreEqual("myname", mi.Name);
       Assert.AreEqual("desc", mi.Description);
       Assert.AreEqual("1", mi.UID);
       Assert.AreEqual(2, mi.Items.Count);
 }
Пример #2
0
        public override void FromXML(XElement xml)
        {
            this.Name = (string)xml.Attribute("name");
              this.Description = (string)xml.Element("menu_description");
              this.UID = (string)xml.Attribute("uid");
              this.Currency = (string)xml.Attribute("currency_symbol");

              XElement itemsElement = xml.Element("menu_groups");
              if (itemsElement != null) {
            this.Groups = new ObservableCollection<MenuGroup>();
            foreach (XElement itemElement in itemsElement.Elements()) {
              var mi = new MenuGroup();
              mi.Menu = this;
              mi.FromXML(itemElement);
              this.Groups.Add(mi);
            }
              }
        }