Bumped package version to 1.5.6 added a helper function to get the name from a enum value.
This commit is contained in:
parent
5e814e81c6
commit
755a2399e4
@ -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.5</Version>
|
<Version>1.5.6</Version>
|
||||||
<PackageReleaseNotes></PackageReleaseNotes>
|
<PackageReleaseNotes></PackageReleaseNotes>
|
||||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
@ -291,9 +291,31 @@ namespace MontoyaTech.Rest.Net
|
|||||||
writer.Outdent().WriteLine("}");
|
writer.Outdent().WriteLine("}");
|
||||||
}
|
}
|
||||||
|
|
||||||
//If this is an enum, generate a GetNames/GetValues function.
|
//If this is an enum, generate a GetNames/GetValues/GetName function.
|
||||||
if (type.IsEnum)
|
if (type.IsEnum)
|
||||||
{
|
{
|
||||||
|
var names = Enum.GetNames(type);
|
||||||
|
|
||||||
|
var values = Enum.GetValues(type);
|
||||||
|
|
||||||
|
//GetName function
|
||||||
|
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.Outdent().WriteLine("*/");
|
||||||
|
writer.WriteLine("static GetName(value) {").Indent();
|
||||||
|
writer.WriteLine("switch (value) {").Indent();
|
||||||
|
|
||||||
|
for (int i = 0; i < values.Length; i++)
|
||||||
|
writer.WriteLine($"case {Convert.ToInt32(values.GetValue(i))}: return `{names.GetValue(i)}`;");
|
||||||
|
|
||||||
|
writer.Outdent().WriteLine("}");
|
||||||
|
writer.WriteLine("return null;");
|
||||||
|
writer.Outdent().WriteLine("}");
|
||||||
|
|
||||||
|
//GetNames function
|
||||||
writer.WriteBreak().WriteLine("/**").Indent();
|
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 in an array.");
|
||||||
writer.WriteLine("@function");
|
writer.WriteLine("@function");
|
||||||
@ -302,13 +324,13 @@ namespace MontoyaTech.Rest.Net
|
|||||||
writer.WriteLine("static GetNames() {").Indent();
|
writer.WriteLine("static GetNames() {").Indent();
|
||||||
writer.WriteLine("return [").Indent();
|
writer.WriteLine("return [").Indent();
|
||||||
|
|
||||||
var names = Enum.GetNames(type);
|
|
||||||
foreach (var name in names)
|
foreach (var name in names)
|
||||||
writer.WriteLine($"'{name}',");
|
writer.WriteLine($"'{name}',");
|
||||||
|
|
||||||
writer.Outdent().WriteLine("];");
|
writer.Outdent().WriteLine("];");
|
||||||
writer.Outdent().WriteLine("}");
|
writer.Outdent().WriteLine("}");
|
||||||
|
|
||||||
|
//GetValues function
|
||||||
writer.WriteBreak().WriteLine("/**").Indent();
|
writer.WriteBreak().WriteLine("/**").Indent();
|
||||||
writer.WriteLine("Returns the values of this enum in an arrray.");
|
writer.WriteLine("Returns the values of this enum in an arrray.");
|
||||||
writer.WriteLine("@function");
|
writer.WriteLine("@function");
|
||||||
@ -317,7 +339,6 @@ namespace MontoyaTech.Rest.Net
|
|||||||
writer.WriteLine("static GetValues() {").Indent();
|
writer.WriteLine("static GetValues() {").Indent();
|
||||||
writer.WriteLine("return [").Indent();
|
writer.WriteLine("return [").Indent();
|
||||||
|
|
||||||
var values = Enum.GetValues(type);
|
|
||||||
foreach (var value in values)
|
foreach (var value in values)
|
||||||
writer.WriteLine($"{Convert.ToInt32(value)},");
|
writer.WriteLine($"{Convert.ToInt32(value)},");
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user