Merge pull request #47 from quamotion/fixes/uid-roundtrip

This commit is contained in:
2018-06-26 13:12:36 +01:00
committed by GitHub
6 changed files with 44 additions and 2 deletions

View File

@@ -21,5 +21,21 @@ namespace plistcil.test
writer.Write(root); writer.Write(root);
} }
} }
[Fact]
public void Roundtrip2Test()
{
byte[] data = File.ReadAllBytes("test-files/plist2.bin");
NSObject root = PropertyListParser.Parse(data);
using (MemoryStream actualOutput = new MemoryStream())
using (Stream expectedOutput = File.OpenRead("test-files/plist2.bin"))
using (ValidatingStream validatingStream = new ValidatingStream(actualOutput, expectedOutput))
{
BinaryPropertyListWriter writer = new BinaryPropertyListWriter(validatingStream);
writer.ReuseObjectIds = false;
writer.Write(root);
}
}
} }
} }

View File

@@ -116,6 +116,9 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Update="test-files\plist2.bin">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="test-files\RoundtripBinaryIndentation.plist"> <None Update="test-files\RoundtripBinaryIndentation.plist">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None> </None>

Binary file not shown.

View File

@@ -25,6 +25,10 @@ namespace Claunia.PropertyList
{ {
return x.Equals(y); return x.Equals(y);
} }
else if (x is NSNumber && BinaryPropertyListWriter.IsSerializationPrimitive((NSNumber)x))
{
return x.Equals(y);
}
else if (x is NSString && BinaryPropertyListWriter.IsSerializationPrimitive((NSString)x)) else if (x is NSString && BinaryPropertyListWriter.IsSerializationPrimitive((NSString)x))
{ {
return x.Equals(y); return x.Equals(y);
@@ -48,6 +52,12 @@ namespace Claunia.PropertyList
return u.GetHashCode(); return u.GetHashCode();
} }
var n = obj as NSNumber;
if (n != null && BinaryPropertyListWriter.IsSerializationPrimitive(n))
{
return n.ToObject().GetHashCode();
}
var s = obj as NSString; var s = obj as NSString;
if (s != null && BinaryPropertyListWriter.IsSerializationPrimitive(s)) if (s != null && BinaryPropertyListWriter.IsSerializationPrimitive(s))
{ {

View File

@@ -240,7 +240,7 @@ namespace Claunia.PropertyList
long[] offsets = new long[idDict.Count]; long[] offsets = new long[idDict.Count];
// write each object, save offset // write each object, save offset
foreach(var pair in idDict) foreach (var pair in idDict)
{ {
NSObject obj = pair.Key; NSObject obj = pair.Key;
int id = pair.Value; int id = pair.Value;
@@ -422,11 +422,18 @@ namespace Claunia.PropertyList
|| content == "$classname" || content == "$classname"
|| content == "NS.objects" || content == "NS.objects"
|| content == "NS.keys" || content == "NS.keys"
|| content == "NSURL"
|| content == "NSDictionary" || content == "NSDictionary"
|| content == "NSObject" || content == "NSObject"
|| content == "NSMutableDictionary" || content == "NSMutableDictionary"
|| content == "NSMutableArray" || content == "NSMutableArray"
|| content == "NSArray"; || content == "NSArray"
|| content == "NSUUID";
}
internal static bool IsSerializationPrimitive(NSNumber n)
{
return n.isBoolean();
} }
} }
} }

View File

@@ -338,6 +338,12 @@ namespace Claunia.PropertyList
{ {
return this.value.GetHashCode(); return this.value.GetHashCode();
} }
/// <inheritdoc/>
public override string ToString()
{
return $"{this.value} (UID)";
}
} }
} }