From 346dcb3ba6c758b757d2e33c6b9cfd235c7b5465 Mon Sep 17 00:00:00 2001 From: oneRain Date: Thu, 7 Jan 2021 15:53:51 +0800 Subject: [PATCH] chore: LCQuery#Get(string objectId) --- Storage/Storage/LCQuery.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Storage/Storage/LCQuery.cs b/Storage/Storage/LCQuery.cs index 928bc1e..c9396f7 100644 --- a/Storage/Storage/LCQuery.cs +++ b/Storage/Storage/LCQuery.cs @@ -346,12 +346,13 @@ namespace LeanCloud.Storage { return (int)ret["count"]; } - public Task Get(string objectId) { + public async Task Get(string objectId) { if (string.IsNullOrEmpty(objectId)) { throw new ArgumentNullException(nameof(objectId)); } - WhereEqualTo("objectId", objectId); - return First(); + string path = $"classes/{ClassName}/{objectId}"; + Dictionary response = await LCApplication.HttpClient.Get>(path); + return DecodeLCObject(response); } public async Task> Find() { @@ -361,9 +362,7 @@ namespace LeanCloud.Storage { List results = response["results"] as List; List list = new List(); foreach (object item in results) { - LCObjectData objectData = LCObjectData.Decode(item as Dictionary); - T obj = LCObject.Create(ClassName) as T; - obj.Merge(objectData); + T obj = DecodeLCObject(item as Dictionary); list.Add(obj); } return list.AsReadOnly(); @@ -412,5 +411,12 @@ namespace LeanCloud.Storage { compositionQuery.ClassName = className; return compositionQuery; } + + private T DecodeLCObject(Dictionary data) { + LCObjectData objectData = LCObjectData.Decode(data); + T obj = LCObject.Create(ClassName) as T; + obj.Merge(objectData); + return obj; + } } }