diff --git a/plist-cil/BinaryPropertyListWriter.cs b/plist-cil/BinaryPropertyListWriter.cs index 77eeab8..b1444d4 100644 --- a/plist-cil/BinaryPropertyListWriter.cs +++ b/plist-cil/BinaryPropertyListWriter.cs @@ -24,7 +24,9 @@ // SOFTWARE. using System; using System.IO; +using System.Linq; using System.Collections.Generic; +using System.Collections.ObjectModel; namespace Claunia.PropertyList { @@ -162,7 +164,7 @@ namespace Claunia.PropertyList long count; // map from object to its ID - Dictionary idMap = new Dictionary(); + Collection idMap = new Collection(); //(new IdentityEqualityComparer()); int idSizeInBytes; /// @@ -220,10 +222,10 @@ namespace Claunia.PropertyList long[] offsets = new long[idMap.Count]; // write each object, save offset - foreach (KeyValuePair entry in idMap) + for(int i = 0; i < idMap.Count; i++) { - NSObject obj = entry.Key; - int id = entry.Value; + NSObject obj = idMap[i]; + int id = i; offsets[id] = count; if (obj == null) { @@ -255,8 +257,7 @@ namespace Claunia.PropertyList // number of objects WriteLong(idMap.Count); // top object - int rootID; - idMap.TryGetValue(root, out rootID); + int rootID = idMap.IndexOf(root); WriteLong(rootID); // offset table offset WriteLong(offsetTableOffset); @@ -267,17 +268,28 @@ namespace Claunia.PropertyList internal void AssignID(NSObject obj) { - if (!idMap.ContainsKey(obj)) + if(obj is UID) { - idMap.Add(obj, idMap.Count); + idMap.Add(obj); + } + else if(!idMap.Contains(obj)) + { + idMap.Add(obj); } } internal int GetID(NSObject obj) { - int ID; - idMap.TryGetValue(obj, out ID); - return ID; + if (obj is UID) + { + var uid = obj as UID; + var first = idMap.OfType().First(v => NSObject.ArrayEquals(v.Bytes, uid.Bytes)); + return idMap.IndexOf(first); + } + else + { + return idMap.IndexOf(obj); + } } static int ComputeIdSizeInBytes(int numberOfIds)