コード例 #1
0
        public async Task <object> Create <T>(
            HttpResponseMessage httpResponseMessage,
            string callId,
            MethodInfo methodInfo)
        {
            var actionReturnType = GeneralHelpers.GetReturnTypeOrGenericArgumentOfTask(methodInfo);
            var resultString     = await httpResponseMessage.Content.ReadAsStringAsync();

            CallDataDto callDataDto = CallDataDictionary.GetData(callId);

            if (callDataDto.Exception != null)
            {
                ExceptionDispatchInfo.Capture(callDataDto.Exception).Throw();
                throw new InvalidOperationException("This is never thrown"); // this line is never reached
            }

            if (actionReturnType == typeof(ActionResult))
            {
                return(new ControllerCallResult(httpResponseMessage, resultString, httpResponseMessage.StatusCode));
            }

            if (GeneralHelpers.IsOrImplements(actionReturnType, typeof(ActionResult <>)))
            {
                var genericTypeOfActionResult = actionReturnType.GenericTypeArguments.First();
                var ridgeResult = GeneralHelpers.CreateInstance(
                    typeof(ControllerCallResult <>).MakeGenericType(genericTypeOfActionResult),
                    httpResponseMessage,
                    resultString,
                    httpResponseMessage.StatusCode,
                    _serializer);
                var actionResult = GeneralHelpers.CreateInstance(actionReturnType, ridgeResult);
                return(actionResult);
            }

            if (GeneralHelpers.IsOrImplements(actionReturnType, typeof(IActionResult)))
            {
                return(new ControllerCallResult(httpResponseMessage, resultString, httpResponseMessage.StatusCode));
            }

            throw new InvalidOperationException($"Controller method must return {nameof(ActionResult)} or {nameof(ActionResult)}<T> or {nameof(IActionResult)}");
        }
コード例 #2
0
ファイル: ResultFactoryForPages.cs プロジェクト: Melchy/Ridge
        public async Task <object> Create <T>(
            HttpResponseMessage httpResponseMessage,
            string callId,
            MethodInfo methodInfo)
        {
            var resultString = await httpResponseMessage.Content.ReadAsStringAsync();

            CallDataDto callDataDto = CallDataDictionary.GetData(callId);

            if (callDataDto.Exception != null)
            {
                ExceptionDispatchInfo.Capture(callDataDto.Exception).Throw();
                throw new InvalidOperationException("This is never thrown"); // this line is never reached
            }

            if (callDataDto.PageModel == null)
            {
                throw new InvalidOperationException("Call data are null.");
            }

            return(new PageResult <T>(httpResponseMessage, (T)callDataDto.PageModel, resultString, httpResponseMessage.StatusCode));
        }