Update XML representation of UIDs

This commit is contained in:
Frederik Carlier
2020-04-23 00:01:27 +02:00
parent 45c043b395
commit 18dbcc3148
2 changed files with 20 additions and 10 deletions

View File

@@ -86,10 +86,11 @@ namespace plistcil.test
string plist = original.ToXmlPropertyList();
// UIDs don't exist in XML property lists, but they are represented as strings
// UIDs don't exist in XML property lists, but they are represented as dictionaries
// for compability purposes
NSString roundtrip = XmlPropertyListParser.ParseString(plist) as NSString;
Assert.Equal("abcd", roundtrip.ToObject());
var roundtrip = XmlPropertyListParser.ParseString(plist) as NSDictionary;
Assert.Single(roundtrip.Keys, "CF$UID");
Assert.Single(roundtrip.Values, new NSNumber(0xabcd));
}
}
}

View File

@@ -148,19 +148,28 @@ namespace Claunia.PropertyList
}
/// <summary>
/// There is no XML representation specified for UIDs.
/// In this implementation UIDs are represented as strings in the XML output.
/// UIDs are represented as dictionaries in XML property lists,
/// where the key is always <c>CF$UID</c> and the value is the integer
/// representation of the UID.
/// </summary>
/// <param name="xml">The xml StringBuilder</param>
/// <param name="level">The indentation level</param>
internal override void ToXml(StringBuilder xml, int level)
{
Indent(xml, level);
xml.Append("<string>");
Span<byte> bytes = stackalloc byte[ByteCount];
GetBytes(bytes);
foreach(byte b in bytes) xml.Append(string.Format("{0:x2}", b));
xml.Append("</string>");
xml.Append("<dict>");
xml.AppendLine();
Indent(xml, level + 1);
xml.Append("<key>CF$UID</key>");
xml.AppendLine();
Indent(xml, level + 1);
xml.Append($"<integer>{this.value}</integer>");
xml.AppendLine();
Indent(xml, level);
xml.Append("</dict>");
}
internal override void ToBinary(BinaryPropertyListWriter outPlist)