protected override ICollection <Expression> GetReturnValueStatements(MethodInfo method, Expression call, Expression resultVariable)
        {
            var        result = base.GetReturnValueStatements(method, call, resultVariable);
            Expression transformedResult;

            if (!method.HasReturnValue())
            {
                transformedResult =
                    Expression.Call(mContinueWithNull, resultVariable);
            }
            else
            {
                Type taskType  = method.ReturnType;
                Type unwrapped = TaskExtensions.UnwrapReturnType(taskType);

                transformedResult =
                    Expression.Call(mCastTaskToNonGeneric.MakeGenericMethod(unwrapped),
                                    Expression.Convert(resultVariable, taskType));
            }

            var assign =
                Expression.Assign(resultVariable, transformedResult);

            result.Add(assign);

            return(result);
        }
Пример #2
0
        private static IWampRpcOperation CreateProgressiveOperation(object instance, MethodInfo method, string procedureUri)
        {
            //return new ProgressiveAsyncMethodInfoRpcOperation<returnType>
            // (instance, method, procedureUri);

            Type returnType =
                TaskExtensions.UnwrapReturnType(method.ReturnType);

            Type operationType =
                typeof(ProgressiveAsyncMethodInfoRpcOperation <>)
                .MakeGenericType(returnType);

            IWampRpcOperation operation =
                (IWampRpcOperation)Activator.CreateInstance(operationType,
                                                            instance,
                                                            method,
                                                            procedureUri);

            return(operation);
        }