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); }
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 = _stringPool[input.ReadInt32()]; 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(_stringPool[input.ReadInt32()])); default: throw new InvalidOperationException(); } }
private PlistDictionary parseBinaryDictionary(int objRef) { var buffer = new PlistDictionary(true); List <int> refs = new List <int>(); int refCount = 0; byte dictByte = objectTable[offsetTable[objRef]]; int refStartPosition; refCount = getCount(offsetTable[objRef], out refStartPosition); if (refCount < 15) { refStartPosition = offsetTable[objRef] + 1; } else { refStartPosition = offsetTable[objRef] + 2 + RegulateNullBytes(BitConverter.GetBytes(refCount), 1).Length; } for (int i = refStartPosition; i < refStartPosition + refCount * 2 * objRefSize; i += objRefSize) { byte[] refBuffer = objectTable.GetRange(i, objRefSize).ToArray(); Array.Reverse(refBuffer); refs.Add(BitConverter.ToInt32(RegulateNullBytes(refBuffer, 4), 0)); } for (int i = 0; i < refCount; i++) { var key = ((PlistString)parseBinary(refs [i])).AsString; var val = parseBinary(refs [i + refCount]); buffer.Add(key, val); } return(buffer); }