예제 #1
0
        private InvocationExpressionSyntax ChainWithFormatters(InvocationExpressionSyntax invocationExpression)
        {
            this.methodRequestInfo
            .WithFormatters
            .ForEach(x =>
            {
                invocationExpression = invocationExpression.ChainWith($"With{x.Key}").WithArgs(x.Value);
            });

            return(invocationExpression);
        }
예제 #2
0
        private InvocationExpressionSyntax ChainWithArguments(InvocationExpressionSyntax invocationExpression, IReadOnlyList <ArgumentSyntax[]> args, string methodName)
        {
            if (args.Count > 0)
            {
                args.ForEach(x =>
                {
                    invocationExpression = invocationExpression.ChainWith(methodName)
                                           .WithArgs(x);
                });
            }

            return(invocationExpression);
        }
예제 #3
0
        private InvocationExpressionSyntax ChainWithRequestUrlBuilding(InvocationExpressionSyntax invocationExpression)
        {
            //Add the UriTemplatePrefix if any.
            if (this.methodRequestInfo.UriTemplatePrefix != null)
            {
                invocationExpression = invocationExpression.ChainWith(nameof(IRestRequest.WithUriTemplatePrefix))
                                       .WithArgs(this.methodRequestInfo.UriTemplatePrefix);
            }

            //Add the UriTemplateSuffix if any.
            if (this.methodRequestInfo.UriTemplateSuffix != null)
            {
                invocationExpression = invocationExpression.ChainWith(nameof(IRestRequest.WithUriTemplateSuffix))
                                       .WithArgs(this.methodRequestInfo.UriTemplateSuffix);
            }

            invocationExpression = invocationExpression.ChainWith(nameof(IRestRequest.WithUriTemplate))
                                   .WithArgs(this.methodRequestInfo.UriTemplate);

            invocationExpression = this.ChainWithUriParameters(invocationExpression);

            return(invocationExpression);
        }
예제 #4
0
        private InvocationExpressionSyntax ChainWithContent(InvocationExpressionSyntax invocationExpression)
        {
            var contents = this.methodRequestInfo.WithContentArguments;

            if (contents.Count > 0)
            {
                contents.ForEach(x =>
                {
                    string methodName = (x is FormUlrEncodedContentArgument) ?
                                        nameof(IRestRequest.WithFormUrlEncodedContent) :
                                        nameof(IRestRequest.WithContent);
                    invocationExpression = invocationExpression.ChainWith(methodName)
                                           .WithArgs(x.Arguments);
                });
            }
            ;

            return(invocationExpression);
        }
예제 #5
0
        private InvocationExpressionSyntax ChainWithSendMethod(InvocationExpressionSyntax invocationExpression, TypeSyntax returnType)
        {
            switch (returnType)
            {
            case null:
                // Task.
                return(invocationExpression.ChainWith(nameof(IRestRequest.SendAsync)));

            case ArrayTypeSyntax type01 when type01.ElementType.GetTypeName() == nameof(Byte):
            case ArrayTypeSyntax type02 when type02.ElementType is PredefinedTypeSyntax elementType &&
                elementType.Keyword.IsKind(SyntaxKind.ByteKeyword):
                // Task<byte[]>.
                return(invocationExpression.ChainWith(nameof(IRestRequest.ReadAsByteArrayAsync)));

            case PredefinedTypeSyntax predefinedType when predefinedType.Keyword.IsKind(SyntaxKind.StringKeyword):
            case var simpleType when simpleType.GetTypeName() == nameof(String):
                // Task<string>.
                return(invocationExpression.ChainWith(nameof(IRestRequest.ReadAsStringAsync)));

            case var type when type.GetTypeName() == nameof(Stream):
                // Task<Stream>.
                return(invocationExpression.ChainWith(nameof(IRestRequest.ReadAsStreamAsync)));

            case PredefinedTypeSyntax predefinedType when predefinedType.Keyword.IsKind(SyntaxKind.BoolKeyword):
            case var simpleType when simpleType.GetTypeName() == nameof(Boolean):
                // Task<bool>.
                return(invocationExpression.ChainWith(nameof(IRestRequest.SendAndGetSuccessAsync)));

            case var simpleType when simpleType.GetTypeName() == nameof(HttpResponseMessage):
                // Task<HttpResponseMessage>.
                return(invocationExpression.ChainWith(nameof(IRestRequest.ReadAsHttpResponseMessageAsync)));

            default:
                // Task<T>.
                return(invocationExpression.ChainWith(nameof(IRestRequest.ReadAsObject), returnType));
            }
        }