feat: support LCCloud.Run<T>

oneRain 2021-03-24 16:24:41 +08:00
parent 4f0d7e9e9f
commit 42729fdddf
3 changed files with 21 additions and 0 deletions

View File

@ -28,6 +28,9 @@ namespace LeanCloud.Common {
return Convert.ToInt32(reader.Value); return Convert.ToInt32(reader.Value);
} }
} }
if (reader.TokenType == JsonToken.Float) {
return Convert.ToSingle(reader.Value);
}
return serializer.Deserialize(reader); return serializer.Deserialize(reader);
} }

View File

@ -28,6 +28,15 @@ namespace Storage.Test {
Assert.AreEqual(response["result"], "Hello, world!"); Assert.AreEqual(response["result"], "Hello, world!");
} }
[Test]
public async Task RunAverageScore() {
float score = await LCCloud.Run<float>("averageStars", new Dictionary<string, object> {
{ "movie", "夏洛特烦恼" }
});
TestContext.WriteLine($"score: {score}");
Assert.True(score.Equals(3.8f));
}
[Test] [Test]
public async Task CallWithoutParams() { public async Task CallWithoutParams() {
await LCCloud.Run("hello"); await LCCloud.Run("hello");

View File

@ -36,6 +36,15 @@ namespace LeanCloud.Storage {
return response; return response;
} }
public static async Task<T> Run<T>(string name,
Dictionary<string, object> parameters = null) {
Dictionary<string, object> response = await Run(name, parameters);
if (response.TryGetValue("result", out object result)) {
return (T)result;
}
return default;
}
/// <summary> /// <summary>
/// Invokes a cloud function as a remote procedure call. /// Invokes a cloud function as a remote procedure call.
/// </summary> /// </summary>