TypescriptEnumGenerator 0.1.0
See the version list below for details.
dotnet add package TypescriptEnumGenerator --version 0.1.0
NuGet\Install-Package TypescriptEnumGenerator -Version 0.1.0
<PackageReference Include="TypescriptEnumGenerator" Version="0.1.0" />
<PackageVersion Include="TypescriptEnumGenerator" Version="0.1.0" />
<PackageReference Include="TypescriptEnumGenerator" />
paket add TypescriptEnumGenerator --version 0.1.0
#r "nuget: TypescriptEnumGenerator, 0.1.0"
#:package TypescriptEnumGenerator@0.1.0
#addin nuget:?package=TypescriptEnumGenerator&version=0.1.0
#tool nuget:?package=TypescriptEnumGenerator&version=0.1.0
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.
Install
tbc.
Example
Given the following input code
[TypescriptEnum] //Decorate your enum with this little badger
public enum TestEnum
{
Active,
Closed,
SomethingElse,
HelloItsMagic
}
And the system will generate the following typescript file
import DropDownOption from './DropDownOption'
export enum TestEnum {
Active = 0,
Closed = 1,
SomethingElse = 2,
HelloItsMagic = 3,
}
export function getTestEnumFromInt(value: number): TestEnum {
switch (value) {
case 0: return TestEnum.Active;
case 1: return TestEnum.Closed;
case 2: return TestEnum.SomethingElse;
case 3: 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 "helloitsmagic": return TestEnum.HelloItsMagic;
default: throw new Error(`Unknown TestEnum value: ${value}`);
}
}
export function getTestEnumDropDownOptions(): DropDownOption[] {
const dropDownOptions = new Array<DropDownOption>();
dropDownOptions.push(new DropDownOption(0, 'Active'));
dropDownOptions.push(new DropDownOption(1, 'Closed'));
dropDownOptions.push(new DropDownOption(2, 'SomethingElse'));
dropDownOptions.push(new DropDownOption(3, 'HelloItsMagic'));
return dropDownOptions;
}
The generator will also generate a single DropDownOption.ts file that is utilized for the GetEnumDropDownOptions method, 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.