TypescriptEnumGenerator 0.2.1
dotnet add package TypescriptEnumGenerator --version 0.2.1
NuGet\Install-Package TypescriptEnumGenerator -Version 0.2.1
<PackageReference Include="TypescriptEnumGenerator" Version="0.2.1" />
<PackageVersion Include="TypescriptEnumGenerator" Version="0.2.1" />
<PackageReference Include="TypescriptEnumGenerator" />
paket add TypescriptEnumGenerator --version 0.2.1
#r "nuget: TypescriptEnumGenerator, 0.2.1"
#:package TypescriptEnumGenerator@0.2.1
#addin nuget:?package=TypescriptEnumGenerator&version=0.2.1
#tool nuget:?package=TypescriptEnumGenerator&version=0.2.1
Typescript Enum Generator
TypescriptEnumGenerator is a package that utilizes the dotnet ISourceGenerator to provide enum types and helper methods for enums. It helps to reduce the overhead of modifying enums throughout your front and back end by generating Typescript types and classes. This assists in maintaining uniformity between C# and TypeScript.
Features
- Helps maintain uniformity between C# and TypeScript enum definitions.
- Provides a clean mechanism for utilizing enums for front end dropdowns, while providing compatibility for most component libraries.
- Integrates into the
[Display]attribute and respects usage of[Display(Name="")
Install
dotnet add package TypescriptEnumGenerator --version 0.2.1
Install-Package TypescriptEnumGenerator -Version 0.2.1
Example
Given the following input code
[TypescriptEnum] //Decorate your enum with this little badger
public enum TestEnum
{
Active,
Closed,
[Display(Name = "Something else")]
SomethingElse = 13,
[Display(Name = "Hello it's magic")]
HelloItsMagic
}
And the system will generate the following typescript file
import DropDownOption from './DropDownOption'
export enum TestEnum {
Active = 0,
Closed = 1,
SomethingElse = 13,
HelloItsMagic = 14,
}
export function getTestEnumFromInt(value: number): TestEnum {
switch (value) {
case 0: return TestEnum.Active;
case 1: return TestEnum.Closed;
case 13: return TestEnum.SomethingElse;
case 14: return TestEnum.HelloItsMagic;
default: throw new Error(`Unknown TestEnum value: ${value}`);
}
}
export function getTestEnumFromString(value: string): TestEnum {
switch (value.toLowerCase()) {
case "active": return TestEnum.Active;
case "closed": return TestEnum.Closed;
case "somethingelse": return TestEnum.SomethingElse;
case "something else": return TestEnum.SomethingElse;
case "helloitsmagic": return TestEnum.HelloItsMagic;
case "hello it's magic": return TestEnum.HelloItsMagic;
default: throw new Error(`Unknown TestEnum value: ${value}`);
}
}
export const TestEnumDropDownOptions: DropDownOption[] = [
new DropDownOption(0, "Active"),
new DropDownOption(1, "Closed"),
new DropDownOption(13, "Something else"),
new DropDownOption(14, "Hello it's magic"),
];
The generator will also generate a single DropDownOption.ts file that is utilized for the DropDownOption class, this is designed to be used with Select and DropDown components provided by most component libraries and the vanilla HTML specification.
export default class DropdownOption {
id: number;
label: string;
constructor(id: number, label: string) {
this.id = id;
this.label = label;
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.