From d084c927211a2a0eb89ea17fff85b0472c36081b Mon Sep 17 00:00:00 2001 From: oneRain Date: Mon, 22 Mar 2021 17:06:39 +0800 Subject: [PATCH] chore: SaveAll/DeleteAll --- Storage/Storage/LCObject.cs | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Storage/Storage/LCObject.cs b/Storage/Storage/LCObject.cs index 76ef2b1..8a20ba9 100644 --- a/Storage/Storage/LCObject.cs +++ b/Storage/Storage/LCObject.cs @@ -349,18 +349,18 @@ namespace LeanCloud.Storage { return this; } - public static async Task> SaveAll(List objectList) { - if (objectList == null) { - throw new ArgumentNullException(nameof(objectList)); + public static async Task> SaveAll(IEnumerable objects) { + if (objects == null) { + throw new ArgumentNullException(nameof(objects)); } - foreach (LCObject obj in objectList) { + foreach (LCObject obj in objects) { if (LCBatch.HasCircleReference(obj, new HashSet())) { throw new ArgumentException("Found a circle dependency when save."); } } - Stack batches = LCBatch.BatchObjects(objectList, true); + Stack batches = LCBatch.BatchObjects(objects, true); await SaveBatches(batches); - return objectList; + return objects.ToList(); } public async Task Delete() { @@ -371,12 +371,11 @@ namespace LeanCloud.Storage { await LCApplication.HttpClient.Delete(path); } - public static async Task DeleteAll(List objectList) { - if (objectList == null || objectList.Count == 0) { - throw new ArgumentNullException(nameof(objectList)); + public static async Task DeleteAll(IEnumerable objects) { + if (objects == null || objects.Count() == 0) { + throw new ArgumentNullException(nameof(objects)); } - IEnumerable objects = objectList.Where(item => item.ObjectId != null); - HashSet objectSet = new HashSet(objects); + HashSet objectSet = new HashSet(objects.Where(item => item.ObjectId != null)); List> requestList = objectSet.Select(item => { string path = $"/{LCApplication.APIVersion}/classes/{item.ClassName}/{item.ObjectId}"; return new Dictionary {