* 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());
}
[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.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<IDictionary<string, object>>(value);
//if (dict != null) {
// var json = new Dictionary<string, object>();
// 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<string, object>();
foreach (var key in dict.Keys) {
object v = dict[key];
json[key.ToString()] = Encode(v);
}
return json;
}
//var list = Conversion.As<IList<object>>(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<string, object> EncodeAVObject(AVObject value);
private object EncodeList(IList<object> list) {
private object EncodeList(IList list) {
List<object> newArray = new List<object>();
foreach (object item in list) {
newArray.Add(Encode(item));