mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 19:14:26 +00:00
Consider booleans to be serialization 'primitives' as well
This commit is contained in:
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
BIN
plist-cil.test/test-files/plist2.bin
Normal file
BIN
plist-cil.test/test-files/plist2.bin
Normal file
Binary file not shown.
@@ -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))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -338,6 +338,12 @@ namespace Claunia.PropertyList
|
|||||||
{
|
{
|
||||||
return this.value.GetHashCode();
|
return this.value.GetHashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{this.value} (UID)";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user