From c352529843858b1ef66f2503322b22a5374f7771 Mon Sep 17 00:00:00 2001 From: oneRain Date: Thu, 5 Dec 2019 16:36:11 +0800 Subject: [PATCH] =?UTF-8?q?*=20ObjectTest.cs:=20chore:=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81=20Pointer=20=E7=B1=BB=E5=9E=8B=E7=9A=84=E6=95=B0?= =?UTF-8?q?=E7=BB=84=E5=92=8C=E5=AD=97=E5=85=B8=E5=8F=8A=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * AVEncoder.cs: --- Storage/Storage.Test/ObjectTest.cs | 13 +++++++++ .../Storage/Internal/Encoding/AVEncoder.cs | 28 ++++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) 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));