From b1c62113656daec6119c2adc30d6ff00ccfc9eb6 Mon Sep 17 00:00:00 2001 From: Mayuki Sawatari Date: Thu, 16 Sep 2021 18:04:43 +0900 Subject: [PATCH 1/2] Add UnaryResult.FromResult() --- src/MagicOnion.Abstractions/UnaryResult.cs | 28 +++++++++++++++++-- .../MagicOnion.Abstractions/UnaryResult.cs | 28 +++++++++++++++++-- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/MagicOnion.Abstractions/UnaryResult.cs b/src/MagicOnion.Abstractions/UnaryResult.cs index 1dee9f3f3..37f548d62 100644 --- a/src/MagicOnion.Abstractions/UnaryResult.cs +++ b/src/MagicOnion.Abstractions/UnaryResult.cs @@ -1,4 +1,4 @@ -using Grpc.Core; +using Grpc.Core; using MagicOnion.Client; using MagicOnion.CompilerServices; // require this using in AsyncMethodBuilder using System; @@ -8,12 +8,34 @@ namespace MagicOnion { /// - /// Wrapped AsyncUnaryCall. + /// Represents the result of a Unary call that wraps AsyncUnaryCall as Task-like. + /// + public static class UnaryResult + { + /// + /// Creates a with the specified result. + /// + public static UnaryResult FromResult(T value) + { + return new UnaryResult(value); + } + + /// + /// Creates a with the specified result task. + /// + public static UnaryResult FromResult(Task task) + { + return new UnaryResult(task); + } + } + + /// + /// Represents the result of a Unary call that wraps AsyncUnaryCall as Task-like. /// #if NON_UNITY || (CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))) [AsyncMethodBuilder(typeof(AsyncUnaryResultMethodBuilder<>))] #endif - public struct UnaryResult + public readonly struct UnaryResult { internal readonly bool hasRawValue; // internal internal readonly TResponse rawValue; // internal diff --git a/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs b/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs index 1dee9f3f3..37f548d62 100644 --- a/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs +++ b/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs @@ -1,4 +1,4 @@ -using Grpc.Core; +using Grpc.Core; using MagicOnion.Client; using MagicOnion.CompilerServices; // require this using in AsyncMethodBuilder using System; @@ -8,12 +8,34 @@ namespace MagicOnion { /// - /// Wrapped AsyncUnaryCall. + /// Represents the result of a Unary call that wraps AsyncUnaryCall as Task-like. + /// + public static class UnaryResult + { + /// + /// Creates a with the specified result. + /// + public static UnaryResult FromResult(T value) + { + return new UnaryResult(value); + } + + /// + /// Creates a with the specified result task. + /// + public static UnaryResult FromResult(Task task) + { + return new UnaryResult(task); + } + } + + /// + /// Represents the result of a Unary call that wraps AsyncUnaryCall as Task-like. /// #if NON_UNITY || (CSHARP_7_OR_LATER || (UNITY_2018_3_OR_NEWER && (NET_STANDARD_2_0 || NET_4_6))) [AsyncMethodBuilder(typeof(AsyncUnaryResultMethodBuilder<>))] #endif - public struct UnaryResult + public readonly struct UnaryResult { internal readonly bool hasRawValue; // internal internal readonly TResponse rawValue; // internal From 2937249203ab747b66a7ad7c14fd8ee53d93ef09 Mon Sep 17 00:00:00 2001 From: Mayuki Sawatari Date: Thu, 16 Sep 2021 18:32:48 +0900 Subject: [PATCH 2/2] Add UnaryResult.Nil --- src/MagicOnion.Abstractions/UnaryResult.cs | 15 +++++++++------ .../MagicOnion.Abstractions/UnaryResult.cs | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/MagicOnion.Abstractions/UnaryResult.cs b/src/MagicOnion.Abstractions/UnaryResult.cs index 37f548d62..49dd68792 100644 --- a/src/MagicOnion.Abstractions/UnaryResult.cs +++ b/src/MagicOnion.Abstractions/UnaryResult.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using MessagePack; namespace MagicOnion { @@ -16,17 +17,19 @@ public static class UnaryResult /// Creates a with the specified result. /// public static UnaryResult FromResult(T value) - { - return new UnaryResult(value); - } + => new UnaryResult(value); /// /// Creates a with the specified result task. /// public static UnaryResult FromResult(Task task) - { - return new UnaryResult(task); - } + => new UnaryResult(task); + + /// + /// Gets the result that contains as the result value. + /// + public static UnaryResult Nil + => new UnaryResult(MessagePack.Nil.Default); } /// diff --git a/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs b/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs index 37f548d62..49dd68792 100644 --- a/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs +++ b/src/MagicOnion.Client.Unity/Assets/Scripts/MagicOnion/MagicOnion.Abstractions/UnaryResult.cs @@ -4,6 +4,7 @@ using System; using System.Runtime.CompilerServices; using System.Threading.Tasks; +using MessagePack; namespace MagicOnion { @@ -16,17 +17,19 @@ public static class UnaryResult /// Creates a with the specified result. /// public static UnaryResult FromResult(T value) - { - return new UnaryResult(value); - } + => new UnaryResult(value); /// /// Creates a with the specified result task. /// public static UnaryResult FromResult(Task task) - { - return new UnaryResult(task); - } + => new UnaryResult(task); + + /// + /// Gets the result that contains as the result value. + /// + public static UnaryResult Nil + => new UnaryResult(MessagePack.Nil.Default); } ///