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

Optimize for member or property addition #4

Closed
TimothyK opened this issue Jun 29, 2017 · 0 comments
Closed

Optimize for member or property addition #4

TimothyK opened this issue Jun 29, 2017 · 0 comments
Milestone

Comments

@TimothyK
Copy link
Owner

When creating a strongly typed enum (or any type of parent/child sub classes) it is worth asking: Is it more likely that I add a new member to the enum or is it more likely that I add a new property. The answer should impact how the code should be designed.

The current generator is optimized more for adding properties. When you add a new property you just need to decide what the new property should return (or behave) for each of the enum members.

Adding a new member is harder. You add the new static readonly field (i.e. the member). Then you need to update every single property for how that property needs to support that new member.

The alternate way of designing the class is so that you specify the all property values on the internal constructor for the class. These are saved as backing instance fields by the constructor. When you define the new member you just add the new member and its call to the constructor with all its properties. There is no need to edit the code for all the existing properties when adding the new member.

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

No branches or pull requests

1 participant