XmlPropertyListParser: Support deserializing UID values

This commit is contained in:
Frederik Carlier
2020-04-27 23:02:28 +02:00
parent 7f98f27448
commit 997e9c3b4c
2 changed files with 24 additions and 13 deletions

View File

@@ -88,9 +88,8 @@ namespace plistcil.test
// UIDs don't exist in XML property lists, but they are represented as dictionaries
// for compability purposes
var roundtrip = XmlPropertyListParser.ParseString(plist) as NSDictionary;
Assert.Single(roundtrip.Keys, "CF$UID");
Assert.Single(roundtrip.Values, new NSNumber(0xabcd));
var roundtrip = XmlPropertyListParser.ParseString(plist) as UID;
Assert.Equal(0xabcdUL, roundtrip.ToUInt64());
}
}
}

View File

@@ -146,6 +146,17 @@ namespace Claunia.PropertyList
static NSObject ParseObject(XmlNode n)
{
if(n.Name.Equals("dict"))
{
// Special case for UID values
if(n.ChildNodes.Count == 2
&& n.ChildNodes[0].Name == "key"
&& n.ChildNodes[0].InnerText == "CF$UID"
&& n.ChildNodes[1].Name == "integer"
&& uint.TryParse(n.ChildNodes[1].InnerText, out uint uidValue))
{
return new UID(uidValue);
}
else
{
NSDictionary dict = new NSDictionary();
List<XmlNode> children = FilterElementNodes(n.ChildNodes);
@@ -161,6 +172,7 @@ namespace Claunia.PropertyList
return dict;
}
}
if(n.Name.Equals("array"))
{