Beispiel #1
0
        /// <summary>
        /// Create the template output
        /// </summary>
        public virtual string TransformText()
        {
            this.Write("//----------------------\r\n// <auto-generated>\r\n//     Generated using the NSwag t" +
                       "oolchain v");

            #line 8 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion));

            #line default
            #line hidden
            this.Write(" (NJsonSchema v");

            #line 8 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(JsonSchema4.ToolchainVersion));

            #line default
            #line hidden
            this.Write(@") (http://NSwag.org)
// </auto-generated>
//----------------------

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.IO;
using System.Linq;
");

            #line 21 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            if (Model.GenerateImplementation)
            {
            #line default
            #line hidden
                this.Write("using System.Net;\r\nusing System.Net.Http;\r\n");

            #line 24 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            }

            #line default
            #line hidden
            this.Write(@"using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Text;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
");

            #line 35 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            foreach (var usage in Model.NamespaceUsages)
            {
            #line default
            #line hidden
                this.Write("using ");

            #line 35 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(usage));

            #line default
            #line hidden
                this.Write(";\r\n");

            #line 36 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("\r\nnamespace ");

            #line 38 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(Model.Namespace));

            #line default
            #line hidden
            this.Write("\r\n{\r\n    #pragma warning disable // Disable all warnings\r\n\r\n    ");

            #line 42 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(Model.Clients, 1)));

            #line default
            #line hidden
            this.Write("\r\n\r\n");

            #line 44 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            if (Model.GenerateContracts)
            {
            #line default
            #line hidden
                this.Write("    ");

            #line 45 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                this.Write(this.ToStringHelper.ToStringWithCulture(ConversionUtilities.Tab(Model.Classes, 1)));

            #line default
            #line hidden
                this.Write("\r\n\r\n\t");

            #line 47 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                if (Model.RequiresFileParameterType)
                {
            #line default
            #line hidden
                    this.Write("    [GeneratedCode(\"NSwag\", \"");

            #line 48 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion));

            #line default
            #line hidden
                    this.Write(@""")]
    public class FileParameter
    {
        public FileParameter(Stream data) 
            : this (data, null)
        {
        }

        public FileParameter(Stream data, string fileName)
        {
            Data = data;
            FileName = fileName;
        }

        public Stream Data { get; private set; }

        public string FileName { get; private set; }
    }
	"    );

            #line 66 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                }

            #line default
            #line hidden
                this.Write("\r\n");

            #line 68 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                foreach (var exceptionClassName in Model.ExceptionClassNames)
                {
            #line default
            #line hidden
                    this.Write("    [GeneratedCode(\"NSwag\", \"");

            #line 69 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion));

            #line default
            #line hidden
                    this.Write("\")]\r\n    public class ");

            #line 70 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(exceptionClassName));

            #line default
            #line hidden
                    this.Write(" : Exception\r\n    {\r\n        public string StatusCode { get; private set; }\r\n\r\n  " +
                               "      public byte[] ResponseData { get; private set; }\r\n\r\n        public ");

            #line 76 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(exceptionClassName));

            #line default
            #line hidden
                    this.Write(@"(string message, string statusCode, byte[] responseData, Exception innerException) 
            : base(message, innerException)
        {
            StatusCode = statusCode;
            ResponseData = responseData;
        }

        public override string ToString()
        {
            return string.Format(""HTTP Response: n{0}n{1}"", Encoding.UTF8.GetString(ResponseData, 0, ResponseData.Length), base.ToString());
        }
    }

    [GeneratedCode(""NSwag"", """);

            #line 89 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerService.ToolchainVersion));

            #line default
            #line hidden
                    this.Write("\")]\r\n    public class ");

            #line 90 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(exceptionClassName));

            #line default
            #line hidden
                    this.Write("<TResponse> : ");

            #line 90 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(exceptionClassName));

            #line default
            #line hidden
                    this.Write("\r\n    {\r\n        public TResponse Response { get; private set; }\r\n\r\n        publi" +
                               "c ");

            #line 94 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(exceptionClassName));

            #line default
            #line hidden
                    this.Write("(string message, string statusCode, byte[] responseData, TResponse response, Exce" +
                               "ption innerException) \r\n            : base(message, statusCode, responseData, in" +
                               "nerException)\r\n        {\r\n            Response = response;\r\n        }\r\n    }\r\n\r\n" +
                               "");

            #line 101 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                }

            #line default
            #line hidden

            #line 102 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            }

            #line default
            #line hidden

            #line 103 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            if (Model.GenerateImplementation)
            {
            #line default
            #line hidden

            #line 104 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                if (Model.RequiresJsonExceptionConverter)
                {
            #line default
            #line hidden
                    this.Write("    ");

            #line 105 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                    this.Write(this.ToStringHelper.ToStringWithCulture(SwaggerToCSharpClientGenerator.GetJsonExceptionConverterCode(1)));

            #line default
            #line hidden
                    this.Write("\r\n");

            #line 106 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
                }

            #line default
            #line hidden

            #line 107 "C:\code\github\nswag\src\NSwag.CodeGeneration\CodeGenerators\CSharp\Templates\FileTemplate.tt"
            }

            #line default
            #line hidden
            this.Write("}");
            return(this.GenerationEnvironment.ToString());
        }