Example #1
0
        public CodeMemberMethod CreateApiFunction(WebApiDescription description, Fonlow.Poco2Client.IPoco2Client poco2TsGen, bool stringAsString)
        {
            this.Description    = description;
            this.Poco2TsGen     = poco2TsGen;
            this.stringAsString = stringAsString;

            NethodName = TsCodeGenerationOptions.Instance.CamelCase ? Fonlow.Text.StringExtensions.ToCamelCase(description.ActionDescriptor.ActionName) : description.ActionDescriptor.ActionName;
            if (NethodName.EndsWith("Async"))
            {
                NethodName = NethodName.Substring(0, NethodName.Length - 5);                //HTTP does not care about the server side async.
            }
            ReturnType = description.ResponseDescription?.ResponseType ?? description.ActionDescriptor.ReturnType;

            //create method
            Method = CreateMethodName();

            CreateDocComments();

            switch (description.HttpMethod)
            {
            case "GET":
            case "DELETE":
            case "POST":
            case "PUT":
                RenderImplementation();
                break;

            default:
                Trace.TraceWarning("This HTTP method {0} is not yet supported", description.HttpMethod);
                break;
            }

            return(Method);
        }
Example #2
0
        public ClientApiFunctionGen(SharedContext sharedContext, WebApiDescription description, Fonlow.Poco2Client.IPoco2Client poco2CsGen)
        {
            this.description   = description;
            this.sharedContext = sharedContext;
            this.poco2CsGen    = poco2CsGen;

            methodName = description.ActionDescriptor.ActionName;
            if (methodName.EndsWith("Async"))
            {
                methodName = methodName.Substring(0, methodName.Length - 5);
            }

            returnType = description.ResponseDescription?.ResponseType ?? description.ActionDescriptor.ReturnType;
        }
        public ClientApiFunctionGen(SharedContext sharedContext, WebApiDescription description, Fonlow.Poco2Client.IPoco2Client poco2CsGen, bool stringAsString, bool forAsync = false)
        {
            this.description    = description;
            this.sharedContext  = sharedContext;
            this.poco2CsGen     = poco2CsGen;
            this.forAsync       = forAsync;
            this.stringAsString = stringAsString;

            methodName = description.ActionDescriptor.ActionName;
            if (methodName.EndsWith("Async"))
            {
                methodName = methodName.Substring(0, methodName.Length - 5);
            }

            returnType         = description.ResponseDescription?.ResponseType ?? description.ActionDescriptor.ReturnType;
            returnTypeIsStream = returnType != null && ((returnType.FullName == typeNameOfHttpResponseMessage) ||
                                                        (returnType.FullName == typeOfIHttpActionResult) ||
                                                        (returnType.FullName == typeOfIActionResult) ||
                                                        (returnType.FullName == typeOfActionResult) ||
                                                        (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.IActionResult")) || // .net core is not translating Task<IActionResult> properly.
                                                        (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.IHttpActionResult")) ||
                                                        (returnType.FullName.StartsWith("System.Threading.Tasks.Task`1[[Microsoft.AspNetCore.Mvc.ActionResult"))
                                                        );
        }
Example #4
0
        public static CodeMemberMethod Create(SharedContext sharedContext, WebApiDescription description, Fonlow.Poco2Client.IPoco2Client poco2CsGen, bool forAsync = false)
        {
            var gen = new ClientApiFunctionGen(sharedContext, description, poco2CsGen);

            return(gen.CreateApiFunction(forAsync));
        }