示例#1
0
        private PlistDictionary LoadDictionaryContents(XmlReader reader, PlistDictionary dict)
        {
            Debug.Assert(reader.NodeType == XmlNodeType.Element && reader.LocalName == "key");
            while (!reader.EOF && reader.NodeType == XmlNodeType.Element)
            {
                //string key = reader.ReadElementString ();
                string key = reader.ReadElementContentAsString();
                while (reader.NodeType != XmlNodeType.Element && reader.Read())
                {
                    if (reader.NodeType == XmlNodeType.EndElement)
                    {
                        throw new Exception(String.Format("No value found for key {0}", key));
                    }
                }
                PlistObjectBase result = LoadFromNode(reader);
                if (result != null)
                {
                    dict.Add(key, result);
                }

                // when there is no whitespace between nodes, we might already be at
                // the next key element, so reading to next sibling would jump over
                // the next (current) key element
                if (!"key".Equals(reader.Name))
                {
                    reader.ReadToNextSibling("key");
                }
            }
            return(dict);
        }
示例#2
0
            protected PlistObjectBase ReadValue(ContentReader input)
            {
                var type = (ValueType)input.ReadByte();

                switch (type)
                {
                case ValueType.Array:
                    var count = input.ReadInt32();
                    var array = new PlistArray(count);
                    for (int i = 0; i < count; i++)
                    {
                        array.Add(ReadValue(input));
                    }
                    return(array);

                case ValueType.Bool:
                    return(new PlistBoolean(input.ReadBoolean()));

                case ValueType.Data:
                    count = input.ReadInt32();
                    return(new PlistData(input.ReadBytes(count)));

                case ValueType.Date:
                    return(new PlistDate(input.ReadObject <DateTime>()));

                case ValueType.Dictionary:
                    count = input.ReadInt32();
                    var dict = new PlistDictionary();
                    for (int i = 0; i < count; i++)
                    {
                        string key = input.ReadString();
                        dict.Add(key, ReadValue(input));
                    }
                    return(dict);

                case ValueType.Integer:
                    return(new PlistInteger(input.ReadInt32()));

                case ValueType.Null:
                    return(new PlistNull());

                case ValueType.Real:
                    return(new PlistReal(input.ReadSingle()));

                case ValueType.String:
                    return(new PlistString(input.ReadString()));

                default:
                    throw new InvalidOperationException();
                }
            }