From 9367ba0ff552dc74601f1a6b94e5b4d013b7dfee Mon Sep 17 00:00:00 2001 From: MattMo Date: Fri, 16 Jun 2023 10:17:21 -0700 Subject: [PATCH] Bumped package version to 1.6.1 and added helper GetValue function to Javascript and improved the documentation. --- Rest.Net.Example/Program.cs | 2 +- Rest.Net/Rest.Net.csproj | 2 +- Rest.Net/RestJavascriptClientGenerator.cs | 30 +++++++++++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Rest.Net.Example/Program.cs b/Rest.Net.Example/Program.cs index 4b46750..01091bd 100644 --- a/Rest.Net.Example/Program.cs +++ b/Rest.Net.Example/Program.cs @@ -72,7 +72,7 @@ namespace MontoyaTech.Rest.Net.Example { File.WriteAllText("test.txt", "hello from a file"); - var listener = new RouteListener(8080, + var listener = new RouteListener(8088, new Route(HttpRequestMethod.Get, "/status", Status), new Route(HttpRequestMethod.Post, "/add/{a}/{b}", Add), new Route(HttpRequestMethod.Get, "/compress", Compress), diff --git a/Rest.Net/Rest.Net.csproj b/Rest.Net/Rest.Net.csproj index a0fd6b7..0b34c6a 100644 --- a/Rest.Net/Rest.Net.csproj +++ b/Rest.Net/Rest.Net.csproj @@ -17,7 +17,7 @@ MontoyaTech.Rest.Net MontoyaTech.Rest.Net True - 1.6.0 + 1.6.1 Logo_Symbol_Black_Outline.png diff --git a/Rest.Net/RestJavascriptClientGenerator.cs b/Rest.Net/RestJavascriptClientGenerator.cs index b49c9e8..5bf9ac7 100644 --- a/Rest.Net/RestJavascriptClientGenerator.cs +++ b/Rest.Net/RestJavascriptClientGenerator.cs @@ -302,8 +302,8 @@ namespace MontoyaTech.Rest.Net writer.WriteBreak().WriteLine("/**").Indent(); writer.WriteLine("Returns the name of a value in this enum. Returns null if the value is invalid."); writer.WriteLine("@function"); - writer.WriteLine("@param {number} value"); - writer.WriteLine("@returns {string}"); + writer.WriteLine("@param {number} value The value to get the name of in this enum."); + writer.WriteLine("@returns {string} The name for the given value."); writer.Outdent().WriteLine("*/"); writer.WriteLine("static GetName(value) {").Indent(); writer.WriteLine("switch (value) {").Indent(); @@ -315,9 +315,29 @@ namespace MontoyaTech.Rest.Net writer.WriteLine("return null;"); writer.Outdent().WriteLine("}"); + //GetValue function + writer.WriteBreak().WriteLine("/**").Indent(); + writer.WriteLine("Returns the value for a name in this enum. Returns null if the name is invalid."); + writer.WriteLine("@function"); + writer.WriteLine("@param {string} name The name of the item in this enum to get the value of."); + writer.WriteLine("@returns {number} The value associated with this name in this enum."); + writer.Outdent().WriteLine("*/"); + writer.WriteLine("static GetValue(name) {").Indent(); + writer.WriteLine("if (!name) {").Indent(); + writer.WriteLine("return null;"); + writer.Outdent().WriteLine("}"); + writer.WriteLine("switch (name.toLowerCase().trim()) {").Indent(); + + for (int i = 0; i < names.Length; i++) + writer.WriteLine($"case '{names.GetValue(i).ToString().ToLower()}': return {values.GetValue(i)};"); + + writer.Outdent().WriteLine("}"); + writer.WriteLine("return null;"); + writer.Outdent().WriteLine("}"); + //GetNames function writer.WriteBreak().WriteLine("/**").Indent(); - writer.WriteLine("Returns the names of this enums values in an array."); + writer.WriteLine("Returns the names of this enums values as an array of strings."); writer.WriteLine("@function"); writer.WriteLine("@returns {Array}"); writer.Outdent().WriteLine("*/"); @@ -332,7 +352,7 @@ namespace MontoyaTech.Rest.Net //GetValues function writer.WriteBreak().WriteLine("/**").Indent(); - writer.WriteLine("Returns the values of this enum in an arrray."); + writer.WriteLine("Returns the values of this enum as an arrray of numbers."); writer.WriteLine("@function"); writer.WriteLine("@returns {Array}"); writer.Outdent().WriteLine("*/"); @@ -348,7 +368,7 @@ namespace MontoyaTech.Rest.Net writer.WriteBreak().WriteLine("/**").Indent(); writer.WriteLine("Returns the names and values of this enum in an array."); writer.WriteLine("@function"); - writer.WriteLine("@returns {Array} Where each element has a name and value key."); + writer.WriteLine("@returns {Array} Where each element is an object and has a name and value field. Ex: { name: '', value: 0 }"); writer.Outdent().WriteLine("*/"); writer.WriteLine("static GetNamesValues() {").Indent(); writer.WriteLine("return [").Indent();