Пример #1
0
        public static Task <T> RequestJsonAsync <T>(this FlurlClient client, object request, CancellationToken cancellationToken = default(CancellationToken), HttpCompletionOption completionOption = HttpCompletionOption.ResponseContentRead)
        {
            var attributes = request.GetType().GetCustomAttributes(typeof(RequestRouteAttribute), false);

            if (attributes != null && attributes.Any())
            {
                var requestRoute = attributes.First() as RequestRouteAttribute;
                switch (requestRoute.Method.ToLower())
                {
                case "get":
                    return(client.GetJsonAsync <T>(requestRoute.RouteTemplate, request, cancellationToken, completionOption));

                default:
                    return(client.PostJsonAsync <T>(requestRoute.RouteTemplate, request, cancellationToken, completionOption));
                }
            }
            else
            {
                throw new ArgumentException("Request dto must have RequestRoute attribute to use with SendAsync.");
            }
        }