Exemplo n.º 1
0
 public static void Serialize(XmlWriter xWrite, ItemType contents)
 {
     XmlSerializer Writer = new XmlSerializer(contents.GetType());
     XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
     ns.Add("", "http://www.hybrasyl.com/XML/Items");
     Writer.Serialize(xWrite, contents, ns);
 }
Exemplo n.º 2
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            JArray    jArray = JArray.Load(reader);
            Inventory inv    = new Inventory(jArray.Count);

            for (byte i = 0; i < jArray.Count; i++)
            {
                XSD.ItemType itmType = null;
                Dictionary <string, object> item;
                if (TryGetValue(jArray[i], out item))
                {
                    itmType = World.Items.Where(x => x.Value.Name == (string)item.FirstOrDefault().Value).FirstOrDefault().Value;
                    if (itmType != null)
                    {
                        inv[i] = new Item(itmType.Id, Game.World)
                        {
                            Count = item.ContainsKey("Count") ? Convert.ToInt32(item["Count"]) : 1
                        };
                        //this will need to be expanded later based on item properties being saved back to the database.
                    }
                }
            }

            return(inv);
        }
Exemplo n.º 3
0
 public static ItemType Deserialize(XmlReader reader, ItemType contents = null)
 {
     //reader.Settings.IgnoreWhitespace = false;
     if (contents == null) contents = new ItemType();
     XmlSerializer XmlSerial = new XmlSerializer(contents.GetType());
     if (XmlSerial.CanDeserialize(reader))
     {
         var xContents = XmlSerial.Deserialize(reader);
         contents = (ItemType)xContents;
     }
     return contents;
 }