/// <summary>Checks if the return is successful and fixes response.</summary> /// <param name="invocation">The invocation.</param> /// <param name="response">The response.</param> /// <exception cref="RemotingException"></exception> /// <exception cref="InvalidCastException">Return type is {response.ReturnValue?.GetType()}</exception> private static void CheckTaskReturn(IInvocation invocation, RpcResponse response) { if (!string.IsNullOrEmpty(response.ErrorInfo)) { throw new RemotingException(response.ErrorInfo, invocation.Method, invocation.Arguments); } if (invocation.Method.ReturnType == typeof(Task)) { return; } Type returnType = invocation.Method.ReturnType.GenericTypeArguments[0]; FixJObject(returnType, response); if (!returnType.IsInstanceOfType(response.ReturnValue)) { throw new InvalidCastException($"Return type is {response.ReturnValue?.GetType()}"); } }
/// <summary>Checks if the return is successful and fixes response.</summary> /// <param name="invocation">The invocation.</param> /// <param name="response">The response.</param> /// <exception cref="RemotingException"></exception> /// <exception cref="InvalidCastException">Return type is {returnType}</exception> private static void CheckReturn(IInvocation invocation, RpcResponse response) { if (!string.IsNullOrEmpty(response.ErrorInfo)) { throw new RemotingException(response.ErrorInfo, invocation.Method, invocation.Arguments); } Type returnType = invocation.Method.ReturnType; FixJObject(returnType, response); if (returnType.IsInstanceOfType(response.ReturnValue)) { return; } if (returnType == typeof(void) && response.ReturnValue is null) { return; } throw new InvalidCastException($"Return type is {returnType}"); }