reinforced / Reinforced.Typings

Converts C# classes to TypeScript interfaces (and many more) within project build. 0-dependency, minimal, gluten-free
MIT License
507 stars 82 forks source link

Export public static properties of static class to enum #251

Open obriankevin11 opened 1 year ago

obriankevin11 commented 1 year ago

Hi,

Is it possible to convert this

MyStaticClass.cs

public static class MyStaticClass
{
    public static readonly string Property1 = "Property1";
    public static readonly string Property2 = "Property2";
}

to

myEnums.ts

export enum MyStaticClass
{
    Property1 = "Property1",
    Property2 = "Property2",
}

?

Thank you!

CrashSensei commented 1 year ago

Instead of using a C# class use a C# enum with the TsEnum UseString option.

[TsEnum(UseString = true)]
public enum MyEnum
{
     Property1,
     Property2
}

This will generate your desired TypeScript enum. To access the string equivilant of the enum in C# simply use the ToString funciton.

MyEnum.Property1.ToString()
obriankevin11 commented 1 year ago

Is there a way to allow more flexibility in naming conventions for enums? What if I have property value such as "x-my-http-header"?