I recently started using enums for commonly used names in my application. The issue is that enums cannot be inherited. This is the intent:
public enum foreignCars
{
Mazda = 0,
Nissan = 1,
Peugot = 2
}
public enum allCars : foreignCars
{
BMW = 3,
VW = 4,
Audi = 5
}
Of course, this can't be done. In similar questions I found, people have suggested using classes for this instead, like:
public static class foreignCars
{
int Mazda = 0;
int Nissan = 1;
int Peugot = 2;
}
public static class allCars : foreignCars
{
int BMW = 3;
int VW = 4;
int Audi = 5;
}
But static classes can't be inherited either! So I would have to make them non-static and create objects just to be able to reference these names in my application, which defeats the whole purpose.
With that in mind, what is the best way to achieve what I want - having inheritable enum-like entities (so that I don't have to repeat car brands in both enums/classes/whatever), and without having to instantiate objects either? What is the proper approach here? This is the part that I couldn't find in any other questions, but if I missed something, please let me know.
EDIT: I would like to point out that I have reviewed similar questions asking about enum and static class inheritance, and I am fully aware that is not possible in C#. Therefore, I am looking for an alternative, which was not covered in these similar questions.