Reinforced.Typings icon indicating copy to clipboard operation
Reinforced.Typings copied to clipboard

Export public static properties of static class to enum

Open obriankevin11 opened this issue 2 years ago • 2 comments

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!

obriankevin11 avatar Dec 05 '22 08:12 obriankevin11

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()

CrashSensei avatar Jan 25 '23 14:01 CrashSensei

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"?

obriankevin11 avatar Aug 25 '23 06:08 obriankevin11