public CodeTypeReference GetBodyType(IMethod method)
            {
                if (method.RequestType.IsNullOrEmpty())
                {
                    return(new CodeTypeReference(typeof(string)));
                }

                return(objectTypeProvider.GetBodyType(method));
            }
Пример #2
0
        public void DecorateClass(IResource resource,
                                  IMethod request,
                                  CodeTypeDeclaration requestClass,
                                  CodeTypeDeclaration resourceClass)
        {
            if (!request.HasBody)
            {
                // Method has no body -> Decorator does not apply.
                return;
            }

            // Add the "Body { get; set; }" property.
            requestClass.Members.AddRange(GenerateBodyProperty(request, objectTypeProvider.GetBodyType(request)));

            // Add the "GetBody()" method override, which returns the body property.
            requestClass.Members.Add(GenerateGetBodyOverride(request));
        }
        internal void AddBodyParameter(CodeConstructor constructor, IMethod request)
        {
            const string varName = "body";

            if (!request.HasBody)
            {
                return; // No body parameter required.
            }

            CodeTypeReference bodyType = objectTypeProvider.GetBodyType(request);
            var thisRef = new CodeThisReferenceExpression();

            // TBody body
            constructor.Parameters.Add(new CodeParameterDeclarationExpression(bodyType, varName));

            // this.Body = body;
            var assign = new CodeAssignStatement();

            assign.Left  = new CodePropertyReferenceExpression(thisRef, BodyPropertyDecorator.BodyPropertyName);
            assign.Right = new CodeVariableReferenceExpression(varName);
            constructor.Statements.Add(assign);
        }
        /// <summary>
        /// Adds code to the class "requestClass" based on the specified "request" method.
        /// </summary>
        public void DecorateClass(IResource resource,
                                  IMethod request,
                                  CodeTypeDeclaration requestClass,
                                  CodeTypeDeclaration resourceClass)
        {
            // Retrieve the response type.
            var requestType = string.IsNullOrEmpty(request.RequestType)
                                   ? new CodeTypeReference(typeof(string))
                                   : objectTypeProvider.GetBodyType(request);

            if (string.IsNullOrEmpty(request.ResponseType))
            {
                var baseRef = new CodeTypeReference(typeof(ResumableUpload <>));
                baseRef.TypeArguments.Add(requestType);
                requestClass.BaseTypes.Add(baseRef);
            }
            else
            {
                var baseRef = new CodeTypeReference(typeof(ResumableUpload <,>));
                baseRef.TypeArguments.Add(requestType);
                baseRef.TypeArguments.Add(objectTypeProvider.GetReturnType(request));
                requestClass.BaseTypes.Add(baseRef);
            }
        }