diff --git a/Storage/Storage.Test/ObjectTest.cs b/Storage/Storage.Test/ObjectTest.cs index 05610e1..6154554 100644 --- a/Storage/Storage.Test/ObjectTest.cs +++ b/Storage/Storage.Test/ObjectTest.cs @@ -280,5 +280,18 @@ namespace LeanCloud.Test { Assert.ThrowsAsync(async () => await a.Save()); } + + [Test] + public async Task SimpleSavePointerCollection() { + AVObject p = new AVObject("P"); + AVObject c1 = new AVObject("C1"); + AVObject c2 = new AVObject("C2"); + p["cList"] = new List { c1, c2 }; + p["cDict"] = new Dictionary { + { "c1", c1 }, + { "c2", c2 } + }; + await p.Save(); + } } } \ No newline at end of file diff --git a/Storage/Storage/Internal/Encoding/AVEncoder.cs b/Storage/Storage/Internal/Encoding/AVEncoder.cs index a05595b..2a104d8 100644 --- a/Storage/Storage/Internal/Encoding/AVEncoder.cs +++ b/Storage/Storage/Internal/Encoding/AVEncoder.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -51,19 +52,20 @@ namespace LeanCloud.Storage.Internal { return jsonConvertible.ToJSON(); } - //var dict = Conversion.As>(value); - //if (dict != null) { - // var json = new Dictionary(); - // foreach (var pair in dict) { - // json[pair.Key] = Encode(pair.Value); - // } - // return json; - //} + if (value is IDictionary) { + IDictionary dict = value as IDictionary; + var json = new Dictionary(); + foreach (var key in dict.Keys) { + object v = dict[key]; + json[key.ToString()] = Encode(v); + } + return json; + } - //var list = Conversion.As>(value); - //if (list != null) { - // return EncodeList(list); - //} + if (value is IList) { + IList list = value as IList; + return EncodeList(list); + } if (value is IAVFieldOperation operation) { return operation.Encode(); @@ -74,7 +76,7 @@ namespace LeanCloud.Storage.Internal { protected abstract IDictionary EncodeAVObject(AVObject value); - private object EncodeList(IList list) { + private object EncodeList(IList list) { List newArray = new List(); foreach (object item in list) { newArray.Add(Encode(item));