Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export public static properties of static class to enum #251

Open
obriankevin11 opened this issue Dec 5, 2022 · 2 comments
Open

Export public static properties of static class to enum #251

obriankevin11 opened this issue Dec 5, 2022 · 2 comments

Comments

@obriankevin11
Copy link

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
Copy link

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
Copy link
Author

obriankevin11 commented Aug 25, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants