Example #1
0
        internal static void InvokeHttpMethod(this IInvocation invocation, ISerializer serializer, Headers headers, InvokeHttpRequest req)
        {
            var returnType = invocation.Method.ReturnType.IsGenericType ? invocation.Method.ReturnType.GetGenericTypeDefinition() : invocation.Method.ReturnType;

            switch (req.HttpMethod)
            {
            case Attributes.HttpMethod.Get:
                if (invocation.MethodInvocationTarget.ReturnType == typeof(void))
                {
                    RestInterceptorUtils.Get(serializer, headers, req);
                }
                else
                {
                    invocation.ReturnValue = RestInterceptorUtils.Get(invocation.MethodInvocationTarget.ReturnType, serializer, headers, req);
                }
                return;

            case Attributes.HttpMethod.Post:
                if (invocation.MethodInvocationTarget.ReturnType == typeof(void))
                {
                    RestInterceptorUtils.Post(serializer, headers, req);
                }
                else
                {
                    invocation.ReturnValue = RestInterceptorUtils.Post(invocation.MethodInvocationTarget.ReturnType, serializer, headers, req);
                }
                return;

            default:
                break;
            }
        }
Example #2
0
        internal static void InvokeHttpMethodAsync(this IInvocation invocation, ISerializer serializer, Headers headers, InvokeHttpRequest req)
        {
            switch (req.HttpMethod)
            {
            case Attributes.HttpMethod.Get:
                if (invocation.Method.ReturnType == typeof(Task))
                {
                    invocation.ReturnValue = RestInterceptorUtils.GetAsync(serializer, headers, req);
                }
                else
                {
                    invocation.ReturnValue = RestInterceptorUtils.GetAsync((dynamic)invocation.ReturnValue, serializer, headers, req);
                }
                break;

            case Attributes.HttpMethod.Post:
                if (invocation.Method.ReturnType == typeof(Task))
                {
                    invocation.ReturnValue = RestInterceptorUtils.PostAsync(serializer, headers, req);
                }
                else
                {
                    invocation.ReturnValue = RestInterceptorUtils.PostAsync((dynamic)invocation.ReturnValue, serializer, headers, req);
                }
                break;

            default:
                break;
            }
        }