示例#1
0
 public HubInvokeMessage(string operationId, string method, HubMethodDefinition methodDefinition, object[] arguments)
 {
     OperationId      = operationId ?? throw new ArgumentNullException(nameof(operationId));
     Method           = method ?? throw new ArgumentNullException(nameof(method));
     MethodDefinition = methodDefinition ?? throw new ArgumentNullException(nameof(methodDefinition));
     Arguments        = arguments ?? throw new ArgumentNullException(nameof(arguments));
 }
示例#2
0
        private static Func <T, HubInvokeMessage, ValueTask <HubInvocationResult> > GetInvokerCore(HubMethodDefinition methodDefinition)
        {
            var returnType = methodDefinition.ReturnType;

            if (returnType == typeof(Task))
            {
                return(InvokeCoreTaskAsync);
            }
            else if (returnType == typeof(ValueTask))
            {
                return(InvokeCoreValueTaskAsync);
            }
            else if (returnType.IsGenericType)
            {
                var openGenericType  = returnType.GetGenericTypeDefinition();
                var actualReturnType = returnType.GetGenericArguments()[0];
                if (openGenericType == typeof(Task <>) || openGenericType == typeof(ValueTask <>))
                {
                    Expression <Func <T, HubInvokeMessage, ValueTask <HubInvocationResult> > > expression = (instance, invokeMessage) => default;

                    var methodCore = openGenericType == typeof(Task <>) ? _methodInfoInvokeCoreTaskAsync : _methodInfoInvokeCoreValueTaskAsync;

                    expression = expression.Update(
                        Expression.Call(null, methodCore.MakeGenericMethod(actualReturnType), expression.Parameters),
                        expression.Parameters
                        );

                    return(expression.Compile());
                }
            }

            return(InvokeCore);
        }
示例#3
0
        public static Func <object, HubInvokeMessage, ValueTask <HubInvocationResult> > GetInvoker(HubMethodDefinition methodDefinition)
        {
            var func = GetInvokerCore(methodDefinition);

            return((instance, invokeMessage) => func((T)instance, invokeMessage));
        }