* ObjectTest.cs: chore: 支持 Pointer 类型的数组和字典及测试

* AVEncoder.cs:
oneRain 2019-12-05 16:36:11 +08:00
parent b85babb38b
commit c352529843
2 changed files with 28 additions and 13 deletions

View File

@ -280,5 +280,18 @@ namespace LeanCloud.Test {
Assert.ThrowsAsync<AVException>(async () => await a.Save()); Assert.ThrowsAsync<AVException>(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<AVObject> { c1, c2 };
p["cDict"] = new Dictionary<string, object> {
{ "c1", c1 },
{ "c2", c2 }
};
await p.Save();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
@ -51,19 +52,20 @@ namespace LeanCloud.Storage.Internal {
return jsonConvertible.ToJSON(); return jsonConvertible.ToJSON();
} }
//var dict = Conversion.As<IDictionary<string, object>>(value); if (value is IDictionary) {
//if (dict != null) { IDictionary dict = value as IDictionary;
// var json = new Dictionary<string, object>(); var json = new Dictionary<string, object>();
// foreach (var pair in dict) { foreach (var key in dict.Keys) {
// json[pair.Key] = Encode(pair.Value); object v = dict[key];
// } json[key.ToString()] = Encode(v);
// return json; }
//} return json;
}
//var list = Conversion.As<IList<object>>(value); if (value is IList) {
//if (list != null) { IList list = value as IList;
// return EncodeList(list); return EncodeList(list);
//} }
if (value is IAVFieldOperation operation) { if (value is IAVFieldOperation operation) {
return operation.Encode(); return operation.Encode();
@ -74,7 +76,7 @@ namespace LeanCloud.Storage.Internal {
protected abstract IDictionary<string, object> EncodeAVObject(AVObject value); protected abstract IDictionary<string, object> EncodeAVObject(AVObject value);
private object EncodeList(IList<object> list) { private object EncodeList(IList list) {
List<object> newArray = new List<object>(); List<object> newArray = new List<object>();
foreach (object item in list) { foreach (object item in list) {
newArray.Add(Encode(item)); newArray.Add(Encode(item));