protected ApiResultBuildOption <T> BuildResultOption <T>(ApiResultBuildOption <T> resultOption) where T : class, new() { var option = resultOption?.Clone() as ApiResultBuildOption <T>; if (option == null) { option = ApiResultBuildOption <T> .Create(this.DefaultResultBuildOption); } else if (this.DefaultRequestBuildOption != null) { } return(option); }
public async Task <ApiResponse <T> > GetAsync <T>(ApiRequest request, string controllerUrl, ApiResultBuildOption <T> resultOption = null) where T : class, new() { var response = new ApiResponse <T>(); try { var task = this.GetAsync(request.GetUrl(controllerUrl)); var message = task.Result; if (resultOption == null && this.DefaultResultBuildOption != null) { resultOption = ApiResultBuildOption <T> .Create(this.DefaultResultBuildOption); } await response.DeserializeMessageAsync(message, resultOption); } catch { response.Data = null; } return(response); }
public async Task <ApiResponse <T> > PostByUrlAsync <T>(string url, ApiResultBuildOption <T> resultOption = null) where T : class, new() { HttpRequestMessage requestMessage = new HttpRequestMessage(); requestMessage.RequestUri = new Uri(url); requestMessage.Method = HttpMethod.Post; var response = new ApiResponse <T>(); try { var task = this.SendAsync(requestMessage); task.Wait(); var message = task.Result; if (resultOption == null && this.DefaultResultBuildOption != null) { resultOption = ApiResultBuildOption <T> .Create(this.DefaultResultBuildOption); } await response.DeserializeMessageAsync(message, resultOption); } catch { response.Data = null; } return(response); }