❔ Encapsulate an enum from legacy code.

Tthevoncarstein2/9/2023
Hi everyone,

I'd like to encapsulate (?) an enum which had a lot of implements in legacy code. I want to modify and add more elements to the enum.
The problem is the legacy code is not ... in a good shape and modifying it directly produces a handful of bugs and time-consuming errors.
I have tried using 2 methods:
- The first one is to make the class that hold the enum become an abstract class and migrate all its code to a derived class. This method helps me a lot with other enum-free classes. But as you know, enum can't be abstract. (Or is it?)
- The second one is to convert the enum to an IComparable class (Like this https://learn.microsoft.com/en-us/dotnet/architecture/microservices/microservice-ddd-cqrs-patterns/enumeration-classes-over-enum-types). But the problem is legacy codes use switch/case which requires constants to compare.

If anyone has experience with this or has some tips or ideas, I would really appreciate your help.
Thank you for taking the time to read my question.
AAntonC2/9/2023
you can use names as strings
AAntonC2/9/2023
or map strings to unique ids
AAntonC2/9/2023
or make those ids constants
AAntonC2/9/2023
and increment the constants manually in the code
AAntonC2/9/2023
there's no other way
AAccord2/10/2023
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.