Questions tagged [enum]
A data type consisting of a set of named values called elements, members or enumerators of the type.
256 questions
4
votes
1
answer
276
views
Hashable and ordered enums to describe states of a process
I am wiriting am application which needs to store information about an industrial process where products go through the following, strictly sequential phases:
...
6
votes
3
answers
381
views
Implementing Generic Enumeration Classes in Domain Layer
I'm developing an ASP.NET Core application using .NET 8, following the Onion Architecture. In our domain model, we use Enumeration classes instead of traditional ...
2
votes
1
answer
78
views
Bidirectional conversion between enum and string in C
I am building an application with a lot of integer values which need to be mapped to strings for user CLI and logging.
Using array LUT does not provide boundary checks so I want to generate conversion ...
5
votes
1
answer
118
views
Replacement for 'enum class' with string functionality
Because I think maintainability can be done better with strings instead of plain enumerator-values when doing fstream IO, I wanted a replacement struct in my project that behaves like an ...
8
votes
3
answers
143
views
Generic overloading bitwise functions to manipulate the enum type
Thanks to G. Sliepen, who gave me a lot very meaningful & useful advice on my implementation about overloading bit operators for a special scoped enum.
Now I have modified the code snippet to ...
4
votes
1
answer
399
views
Better way to add attributes to an enum in Rust for code scalability
I watched a YouTube video (https://www.youtube.com/watch?v=z-0-bbc80JM) talking about the power of enums in rust for data modelling. In the video, there's an example of a state machine of a simple ...
2
votes
0
answers
157
views
"Better" enumeration for C#
I've been looking to have "smarter" or "better" enum functionality in C#. There are a few GitHub/NuGet projects out there, but they seem to target newer versions of .NET and I ...
2
votes
3
answers
234
views
Java Clean Code, use of enums in data structure
I have defined a data structure in Java that allows to manage certain type of elements like a Queue, with the special feature of using 2 inner rows (windows) to attend elements:
...
2
votes
1
answer
88
views
string compatible enum-like structure
So I've decided to flex showcase my "enum that accepts strings etc..." here.
I don't know if it's great but I'm pretty sure it's decent. It is implemented in less than 200 lines of code (not ...
0
votes
3
answers
167
views
Declaring type definition once for all variables
To avoid the use of magic numbers, I created a static class to store some integer values that are represented inside a database. I avoided using enums because I need to cast them every time I use them....
4
votes
1
answer
1k
views
C++ enum to string conversion utility
I needed to find a way to convert a bunch of enums to string for displaying in C++. The two main ways I found when searching was using dark magic macros or voodoo magic template metaprogramming.
As I ...
2
votes
4
answers
175
views
How to refactor function with string inputs to select a "mode" to avoid magic strings?
See code from this question about the advantages of Enums.
...
1
vote
3
answers
107
views
Extensible error code infrastructure
I was answering a question, Java Exception Error Enumerations Anti-pattern, on Software Engineering Stack Exchange and found myself writing up a fair bit of code. It could use a code review so I'm ...
4
votes
3
answers
2k
views
Switch case on an enum to return a specific mapped object from IMapper
I have an ever growing switch case statement I plan on adding 3 more case statements to. Given an int, compare it to an enum, and call ...
5
votes
3
answers
8k
views
Discussing approaches for converting Enum to String
I need to convert the ENUM to a respective string value for which I came up with two approaches and I'm trying to see why would a second approach be better than the first one if even in terms of ...