Fixed a csharp client generator bug. The csharp client generator now outputs a constructor for types that allows setting property/fields. Bumped package version to 1.5.7
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | //Generated using MontoyaTech.Rest.Net | ||||||
| using System; | using System; | ||||||
| using System.Net; | using System.Net; | ||||||
| using System.Net.Http; | using System.Net.Http; | ||||||
| @@ -48,7 +49,7 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/status"); |             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/status"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
| @@ -69,7 +70,7 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Post, $"{StaticClient.BaseUrl}/add/{a}/{b}"); |             var message = new HttpRequestMessage(HttpMethod.Post, $"{StaticClient.BaseUrl}/add/{a}/{b}"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
| @@ -90,7 +91,7 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/compress"); |             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/compress"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
| @@ -111,7 +112,7 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/file/compress"); |             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/file/compress"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
| @@ -135,7 +136,7 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth/{name}"); |             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth/{name}"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
| @@ -158,7 +159,7 @@ public class StaticClient | |||||||
|  |  | ||||||
|             message.Content = new StringContent(JsonConvert.SerializeObject(request)); |             message.Content = new StringContent(JsonConvert.SerializeObject(request)); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (!response.IsSuccessStatusCode) |             if (!response.IsSuccessStatusCode) | ||||||
|                 throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode); |                 throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode); | ||||||
| @@ -168,7 +169,7 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth"); |             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
| @@ -189,7 +190,7 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth/role"); |             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/auth/role"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
| @@ -217,7 +218,7 @@ public class StaticClient | |||||||
|  |  | ||||||
|             message.Content = new StreamContent(request); |             message.Content = new StreamContent(request); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (!response.IsSuccessStatusCode) |             if (!response.IsSuccessStatusCode) | ||||||
|                 throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode); |                 throw new Exception("Unexpected Http Response StatusCode:" + response.StatusCode); | ||||||
| @@ -227,15 +228,13 @@ public class StaticClient | |||||||
|         { |         { | ||||||
|             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/download"); |             var message = new HttpRequestMessage(HttpMethod.Get, $"{StaticClient.BaseUrl}/download"); | ||||||
|  |  | ||||||
|             var response = StaticClient.HttpClient.Send(message); |             var response = StaticClient.HttpClient.Send(message, HttpCompletionOption.ResponseHeadersRead); | ||||||
|  |  | ||||||
|             if (response.IsSuccessStatusCode) |             if (response.IsSuccessStatusCode) | ||||||
|             { |             { | ||||||
|                 var stream = new System.IO.MemoryStream(); |                 var stream = new System.IO.MemoryStream(); | ||||||
|  |  | ||||||
|                 response.Content.ReadAsStream().CopyTo(stream); |                 response.Content.CopyToAsync(stream).GetAwaiter().GetResult(); | ||||||
|  |  | ||||||
|                 stream.Seek(0, System.IO.SeekOrigin.Begin); |  | ||||||
|  |  | ||||||
|                 return stream; |                 return stream; | ||||||
|             } |             } | ||||||
| @@ -249,6 +248,18 @@ public class StaticClient | |||||||
|     public class IncludedType |     public class IncludedType | ||||||
|     { |     { | ||||||
|         public int Test; |         public int Test; | ||||||
|  |  | ||||||
|  |         public IncludedType() { } | ||||||
|  |  | ||||||
|  |         public IncludedType(IncludedType instance) | ||||||
|  |         { | ||||||
|  |             this.Test = instance.Test; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public IncludedType(int Test = 0) | ||||||
|  |         { | ||||||
|  |             this.Test = Test; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public class UserDto : BaseUser |     public class UserDto : BaseUser | ||||||
| @@ -259,23 +270,79 @@ public class StaticClient | |||||||
|  |  | ||||||
|         public System.Collections.Generic.List<string> List; |         public System.Collections.Generic.List<string> List; | ||||||
|  |  | ||||||
|  |         public System.String[] Array; | ||||||
|  |  | ||||||
|         public ulong Property { get; set; } |         public ulong Property { get; set; } | ||||||
|  |  | ||||||
|  |         public UserDto() { } | ||||||
|  |  | ||||||
|  |         public UserDto(UserDto instance) | ||||||
|  |         { | ||||||
|  |             this.MachineType = instance.MachineType; | ||||||
|  |             this.Name = instance.Name; | ||||||
|  |             this.List = instance.List; | ||||||
|  |             this.Array = instance.Array; | ||||||
|  |             this.Property = instance.Property; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public UserDto(System.PlatformID MachineType = 0, string Name = null, System.Collections.Generic.List<string> List = null, System.String[] Array = null, ulong Property = 0) | ||||||
|  |         { | ||||||
|  |             this.MachineType = MachineType; | ||||||
|  |             this.Name = Name; | ||||||
|  |             this.List = List; | ||||||
|  |             this.Array = Array; | ||||||
|  |             this.Property = Property; | ||||||
|  |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public class BaseUser |     public class BaseUser | ||||||
|     { |     { | ||||||
|         public string Id; |         public string Id; | ||||||
|  |  | ||||||
|  |         public char FirstInitial; | ||||||
|  |  | ||||||
|         public System.Collections.Generic.List<Permission> Permissions; |         public System.Collections.Generic.List<Permission> Permissions; | ||||||
|  |  | ||||||
|         public UserRole Role { get; set; } |         public UserRole Role { get; set; } | ||||||
|  |  | ||||||
|  |         public BaseUser() { } | ||||||
|  |  | ||||||
|  |         public BaseUser(BaseUser instance) | ||||||
|  |         { | ||||||
|  |             this.Id = instance.Id; | ||||||
|  |             this.FirstInitial = instance.FirstInitial; | ||||||
|  |             this.Permissions = instance.Permissions; | ||||||
|  |             this.Role = instance.Role; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public BaseUser(string Id = null, char FirstInitial = '\0', System.Collections.Generic.List<Permission> Permissions = null, UserRole Role = 0) | ||||||
|  |         { | ||||||
|  |             this.Id = Id; | ||||||
|  |             this.FirstInitial = FirstInitial; | ||||||
|  |             this.Permissions = Permissions; | ||||||
|  |             this.Role = Role; | ||||||
|  |         } | ||||||
|  |  | ||||||
|         public class Permission |         public class Permission | ||||||
|         { |         { | ||||||
|             public string Name; |             public string Name; | ||||||
|  |  | ||||||
|             public Types Type; |             public Types Type; | ||||||
|  |  | ||||||
|  |             public Permission() { } | ||||||
|  |  | ||||||
|  |             public Permission(Permission instance) | ||||||
|  |             { | ||||||
|  |                 this.Name = instance.Name; | ||||||
|  |                 this.Type = instance.Type; | ||||||
|  |             } | ||||||
|  |  | ||||||
|  |             public Permission(string Name = null, Types Type = 0) | ||||||
|  |             { | ||||||
|  |                 this.Name = Name; | ||||||
|  |                 this.Type = Type; | ||||||
|  |             } | ||||||
|  |  | ||||||
|             public enum Types : int |             public enum Types : int | ||||||
|             { |             { | ||||||
|                 Read = 0, |                 Read = 0, | ||||||
|   | |||||||
| @@ -219,7 +219,7 @@ namespace MontoyaTech.Rest.Net.Example | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         [RouteGroup("Stream")] |         [RouteGroup("Stream")] | ||||||
|         [RouteResponse(typeof(FileStream), Parameter = true)] |         [RouteResponse(typeof(MemoryStream), Parameter = false)] | ||||||
|         public static HttpListenerResponse Download(HttpListenerContext context) |         public static HttpListenerResponse Download(HttpListenerContext context) | ||||||
|         { |         { | ||||||
|             return context.Response.WithStatus(HttpStatusCode.OK).WithText("Hello world"); |             return context.Response.WithStatus(HttpStatusCode.OK).WithText("Hello world"); | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ | |||||||
|     <AssemblyName>MontoyaTech.Rest.Net</AssemblyName> |     <AssemblyName>MontoyaTech.Rest.Net</AssemblyName> | ||||||
|     <RootNamespace>MontoyaTech.Rest.Net</RootNamespace> |     <RootNamespace>MontoyaTech.Rest.Net</RootNamespace> | ||||||
|     <GenerateDocumentationFile>True</GenerateDocumentationFile> |     <GenerateDocumentationFile>True</GenerateDocumentationFile> | ||||||
|     <Version>1.5.6</Version> |     <Version>1.5.7</Version> | ||||||
|     <PackageReleaseNotes></PackageReleaseNotes> |     <PackageReleaseNotes></PackageReleaseNotes> | ||||||
|     <PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon> |     <PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon> | ||||||
|   </PropertyGroup> |   </PropertyGroup> | ||||||
|   | |||||||
| @@ -236,6 +236,27 @@ namespace MontoyaTech.Rest.Net | |||||||
|                     writer.WriteLine($"this.{property.Name} = instance.{property.Name};"); |                     writer.WriteLine($"this.{property.Name} = instance.{property.Name};"); | ||||||
|  |  | ||||||
|                 writer.Outdent().WriteLine('}'); |                 writer.Outdent().WriteLine('}'); | ||||||
|  |  | ||||||
|  |                 //Generate a constructor to set all the fields/properties with optional default values | ||||||
|  |                 writer.WriteBreak(); | ||||||
|  |                 writer.Write($"public {(newName != null ? newName.Name : type.Name)}("); | ||||||
|  |  | ||||||
|  |                 foreach (var field in fields) | ||||||
|  |                     writer.WriteSeparator().Write($"{this.GetTypeFullyResolvedName(field.FieldType)} {field.Name} = {this.GetTypeDefaultValue(field.FieldType)}"); | ||||||
|  |  | ||||||
|  |                 foreach (var property in properties) | ||||||
|  |                     writer.WriteSeparator().Write($"{this.GetTypeFullyResolvedName(property.PropertyType)} {property.Name} = {this.GetTypeDefaultValue(property.PropertyType)}"); | ||||||
|  |  | ||||||
|  |                 writer.WriteLine(")"); | ||||||
|  |                 writer.WriteLine('{').Indent(); | ||||||
|  |  | ||||||
|  |                 foreach (var field in fields) | ||||||
|  |                     writer.WriteLine($"this.{field.Name} = {field.Name};"); | ||||||
|  |  | ||||||
|  |                 foreach (var property in properties) | ||||||
|  |                     writer.WriteLine($"this.{property.Name} = {property.Name};"); | ||||||
|  |  | ||||||
|  |                 writer.Outdent().WriteLine('}'); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             //Generate C# for any types that belong to this one. |             //Generate C# for any types that belong to this one. | ||||||
|   | |||||||
| @@ -356,7 +356,7 @@ namespace MontoyaTech.Rest.Net | |||||||
|             else if (typeCode == TypeCode.String || typeCode == TypeCode.Object) |             else if (typeCode == TypeCode.String || typeCode == TypeCode.Object) | ||||||
|                 return "null"; |                 return "null"; | ||||||
|             else if (typeCode == TypeCode.Char) |             else if (typeCode == TypeCode.Char) | ||||||
|                 return "'\0'"; |                 return "'\\0'"; | ||||||
|             else |             else | ||||||
|                 return Activator.CreateInstance(type).ToString(); |                 return Activator.CreateInstance(type).ToString(); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user