mirror of
https://github.com/claunia/plist-cil.git
synced 2025-12-16 11:04:26 +00:00
Allow NSObject Wrap to handle lists of maps/dicts.
Add corresponding test case.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
// plist-cil - An open source library to Parse and generate property lists for .NET
|
// plist-cil - An open source library to Parse and generate property lists for .NET
|
||||||
// Copyright (C) 2015 Natalia Portillo
|
// Copyright (C) 2015 Natalia Portillo
|
||||||
//
|
//
|
||||||
// This code is based on:
|
// This code is based on:
|
||||||
@@ -209,6 +209,16 @@ namespace plistcil.test
|
|||||||
map.Add("long", lng);
|
map.Add("long", lng);
|
||||||
map.Add("date", date);
|
map.Add("date", date);
|
||||||
|
|
||||||
|
List<Dictionary<string,object>> listOfMaps = new()
|
||||||
|
{
|
||||||
|
new Dictionary<string, object>
|
||||||
|
{
|
||||||
|
{ "int", i },
|
||||||
|
{ "long", lng },
|
||||||
|
{ "date", date }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var WrappedO = NSObject.Wrap((object)bl);
|
var WrappedO = NSObject.Wrap((object)bl);
|
||||||
Assert.True(WrappedO is (NSNumber));
|
Assert.True(WrappedO is (NSNumber));
|
||||||
Assert.True(WrappedO.ToObject().Equals(bl));
|
Assert.True(WrappedO.ToObject().Equals(bl));
|
||||||
@@ -274,6 +284,15 @@ namespace plistcil.test
|
|||||||
Assert.True(((NSNumber)dict.ObjectForKey("long")).ToLong() == lng);
|
Assert.True(((NSNumber)dict.ObjectForKey("long")).ToLong() == lng);
|
||||||
Assert.True(((NSDate)dict.ObjectForKey("date")).Date.Equals(date));
|
Assert.True(((NSDate)dict.ObjectForKey("date")).Date.Equals(date));
|
||||||
|
|
||||||
|
WrappedO = NSObject.Wrap((object)listOfMaps);
|
||||||
|
Assert.True(WrappedO is (NSArray));
|
||||||
|
var arrayOfMaps = (NSArray)WrappedO;
|
||||||
|
Assert.True(arrayOfMaps.Count == 1);
|
||||||
|
var firstMap = (NSDictionary)arrayOfMaps[0];
|
||||||
|
Assert.True(((NSNumber)firstMap.ObjectForKey("int")).ToLong() == i);
|
||||||
|
Assert.True(((NSNumber)firstMap.ObjectForKey("long")).ToLong() == lng);
|
||||||
|
Assert.True(((NSDate)firstMap.ObjectForKey("date")).Date.Equals(date));
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
/*
|
/*
|
||||||
Object unWrappedO = WrappedO.ToObject();
|
Object unWrappedO = WrappedO.ToObject();
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// plist-cil - An open source library to parse and generate property lists for .NET
|
// plist-cil - An open source library to parse and generate property lists for .NET
|
||||||
// Copyright (C) 2015 Natalia Portillo
|
// Copyright (C) 2015 Natalia Portillo
|
||||||
//
|
//
|
||||||
// This code is based on:
|
// This code is based on:
|
||||||
@@ -321,6 +321,14 @@ namespace Claunia.PropertyList
|
|||||||
if(typeof(List<object>).IsAssignableFrom(c))
|
if(typeof(List<object>).IsAssignableFrom(c))
|
||||||
return Wrap(((List<object>)o).ToArray());
|
return Wrap(((List<object>)o).ToArray());
|
||||||
|
|
||||||
|
if(typeof(List<Dictionary<string, object>>).IsAssignableFrom(c))
|
||||||
|
{
|
||||||
|
var list = new NSArray();
|
||||||
|
foreach(Dictionary<string, object> dict in (List<Dictionary<string, object>>)o)
|
||||||
|
list.Add(Wrap(dict));
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
throw new PropertyListException($"Cannot wrap an object of type {o.GetType().Name}.");
|
throw new PropertyListException($"Cannot wrap an object of type {o.GetType().Name}.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user