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

Specifying generated enum value types #40

Closed
maxmalmgren opened this issue Dec 11, 2018 · 3 comments

Comments

Projects
None yet
2 participants
@maxmalmgren
Copy link

commented Dec 11, 2018

In my project we use enums serialized as strings. It would be great if it was possible to specify string value generation, to support the following generated TypeScript:

export enum EnumExample {
    ExampleValue1 = "ExampleValue1",
    ExampleValue2 = "ExampleValue2"
}

Such a feature should probably include the possibility to support different casings between name and value.

I didn't find anything in GeneratorOptions which hints to this.

Thanks for a neat piece of software!

@jburzynski

This comment has been minimized.

Copy link
Owner

commented Dec 12, 2018

You're welcome!

This would be useful. I've added it as a feature for the next release, which will probably be out somewhere towards the end of December.

@jburzynski

This comment has been minimized.

Copy link
Owner

commented Dec 27, 2018

I added enum string initializers in 2.1.0. You can switch them on in tgconfig.json:

{
  "enumStringInitializers": true
}

You can also specify converters that convert C# enum value name to a string initializer (by default string value is exactly the same as C# enum value):

{
  "enumStringInitializersConverters": ["SomeCaseToSomeOtherCase", "..."]
}

There is also an attribute you can use on a single C# enum to opt-in/out to the initializers:

// opt-in

[TsStringInitializers]
public enum MyEnum {}

// opt-out

[TsStringInitializers(false)]
public enum MyEnum {}

On a side note, I also implemented "generation specs" in 2.1.0, which means you can use a configuration file instead of attributes to select C# types to generate:

public class MyGenerationSpec : GenerationSpec
{
  public MyGenerationSpec()
  {
    AddClass<MyClass>();
    AddInterface<MyInterface>();
    // ...
  }
}

You can read more on them in the docs - maybe you can find this useful.

Have a happy new year! :)

@jburzynski

This comment has been minimized.

Copy link
Owner

commented Jan 2, 2019

Closed due to inactivity.

@jburzynski jburzynski closed this Jan 2, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.