Bumped package version to 1.5.1, added GetNames/GetValues helper functions to Javascript Enum Type class.

This commit is contained in:
MattMo 2023-04-14 06:38:01 -07:00
parent fe5fc73d14
commit bbd38496da
2 changed files with 36 additions and 1 deletions

View File

@ -17,7 +17,7 @@
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>1.5.0</Version>
<Version>1.5.1</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
</PropertyGroup>

View File

@ -289,6 +289,41 @@ namespace MontoyaTech.Rest.Net
writer.Outdent().WriteLine("}");
}
//If this is an enum, generate a GetNames/GetValues function.
if (type.IsEnum)
{
writer.WriteBreak().WriteLine("/**").Indent();
writer.WriteLine("Returns the names of this enums values in an array.");
writer.WriteLine("@method");
writer.WriteLine("@returns {Array<string>}");
writer.Outdent().WriteLine("*/");
writer.WriteLine("static GetNames() {").Indent();
writer.WriteLine("return [").Indent();
var names = Enum.GetNames(type);
foreach (var name in names)
writer.WriteLine($"'{name}',");
writer.Outdent().WriteLine("];");
writer.Outdent().WriteLine("}");
writer.WriteBreak().WriteLine("/**").Indent();
writer.WriteLine("Returns the values of this enum in an arrray.");
writer.WriteLine("@method");
writer.WriteLine("@returns {Array<number>}");
writer.Outdent().WriteLine("*/");
writer.WriteLine("static GetValues() {").Indent();
writer.WriteLine("return [").Indent();
var values = Enum.GetValues(type);
foreach (var value in values)
writer.WriteLine($"{Convert.ToInt32(value)},");
writer.Outdent().WriteLine("];");
writer.Outdent().WriteLine("}");
}
//Close off the class
writer.Outdent().WriteLine("}");
writer.WriteBreak().WriteLine($"{this.ClientName}.{(type.DeclaringType != null ? type.DeclaringType.Name : "")}{(newName != null ? newName.Name : type.Name)} = {(type.DeclaringType != null ? type.DeclaringType.Name : "")}{(newName != null ? newName.Name : type.Name)};");