mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 11:04:26 +00:00
Merge pull request #65 from quamotion/fixes/uid-xml
Update XML representation of UIDs
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user