Skip to main content
Filter by
Sorted by
Tagged with
1 vote
6 answers
223 views

I've been studying Java for some time now to better understand what goes on inside some of the code parts. While studying Enum, which I am used to using exclusively for listing various fixed values (...
Ice K's user avatar
  • 37
1 vote
1 answer
104 views

Given the base class: public abstract class EnumType<TEnum, TValue> where TEnum : struct, IConvertible where TValue : struct { public abstract TEnum GetEnumValue(TValue value); } ...
Weifen Luo's user avatar
Advice
0 votes
0 replies
23 views

I'm trying to generate a C# client from the OpenRouter OpenAPI spec: https://github.com/OpenRouterTeam/typescript-sdk/blob/main/.speakeasy/in.openapi.yaml Among other things there are some enums ...
k2042's user avatar
  • 1
0 votes
2 answers
154 views

Clang's -Wassign-enum diagnostic flag will trigger a warning when using an int whose value is out of scope of an enum's cases: typedef enum Foo { FooA, FooB, } Foo; void handleFoo(Foo foo); ...
an0's user avatar
  • 17.6k
2407 votes
32 answers
1.7m views

Say I have an enum which is just public enum Blah { A, B, C, D } and I would like to find the enum value of a string, for example "A" which would be Blah.A. How would it be possible to ...
Malachi's user avatar
  • 33.9k
735 votes
45 answers
1.1m views

I would like to iterate a TypeScript enum object and get each enumerated symbol name, for example: enum myEnum { entry1, entry2 } for (var entry in myEnum) { // use entry's name here, e.g., "...
CalvinDale's user avatar
  • 9,851
1472 votes
31 answers
813k views

I have a class that contains an enum property, and upon serializing the object using JavaScriptSerializer, my json result contains the integer value of the enumeration rather than its string "...
Omer Bokhari's user avatar
1140 votes
43 answers
1.3m views

I'm mainly a C# developer, but I'm currently working on a project in Python. How can I represent the equivalent of an Enum in Python?
1468 votes
22 answers
532k views

I'm building a function to extend the Enum.Parse concept that Allows a default value to be parsed in case that an Enum value is not found Is case insensitive So I wrote the following: public static ...
johnc's user avatar
  • 40.5k
575 votes
34 answers
397k views

Contrary to all other similar questions, this question is about using the new C++ features. 2008 c Is there a simple way to convert C++ enum to string? 2008 c Easy way to use variables of enum types ...
oHo's user avatar
  • 55.1k
963 votes
37 answers
832k views

I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION = 2, SINGLESIGNON = 3 } The problem however is that I need the word "FORMS" ...
user29964's user avatar
  • 16k
2 votes
2 answers
157 views

Niche optimization allows Rust to store data in the invalid bit patterns of a type. The only valid values of a bool are 0 and 1 (one bit). And Result only has two variants (one bit). So why does ...
BallpointBen's user avatar
  • 15.6k
291 votes
33 answers
562k views

I have an enum defined this way: export enum GoalProgressMeasurements { Percentage = 1, Numeric_Target = 2, Completed_Tasks = 3, Average_Milestone_Progress = 4, Not_Measured = 5 } ...
AnimaSola's user avatar
  • 7,936
4 votes
3 answers
424 views

We use protocol buffers both for gRPC server-to-server communication and for publishing messages to Pub/Sub. Pub/Sub is fairly sensitive to schema changes, not allowing any schema changes that would ...
Mike Williamson's user avatar
0 votes
5 answers
3k views

TypeScript has added the erasableSyntaxOnly flag, that doesn't let you use Enums. Have looked for several alternative options. Like: What's the best practice to implement an alternative to ...
Chen Peleg's user avatar
  • 3,190
824 votes
15 answers
700k views

I'm trying to represent a simplified chromosome, which consists of N bases, each of which can only be one of {A, C, T, G}. I'd like to formalize the constraints with an enum, but I'm wondering what ...
carbocation's user avatar
  • 9,648
3 votes
1 answer
70 views

I am writing a Python config script that creates an array of input files in a domain-specific language (DSL), so my use case is a bit unusual. In this scenario, we want medium-level users to be able ...
globglogabgalab's user avatar
1110 votes
13 answers
472k views

I don't think I fundamentally understand what an enum is, and when to use it. For example: typedef enum { kCircle, kRectangle, kOblateSpheroid } ShapeType; What is really being ...
Craig's user avatar
  • 16.3k
260 votes
22 answers
317k views

I'm rebuilding an old Java project in Javascript, and realized that there's no good way to do enums in JS. The best I can come up with is: const Colors = { RED: Symbol("red"), BLUE: ...
cypherfunc's user avatar
  • 2,808
1 vote
0 answers
49 views

I am in a scenario (that could be compared to writing an AST) where I compile multiple regex patterns that I want to reuse later, and for the sake of simplicity and readability I want to store them in ...
globglogabgalab's user avatar
395 votes
10 answers
353k views

What's the correct way to convert a string to a corresponding instance of an Enum subclass? Seems like getattr(YourEnumType, str) does the job, but I'm not sure if it's safe enough. As an example, ...
Vladius's user avatar
  • 4,947
227 votes
32 answers
198k views

Before enums were available in Dart I wrote some cumbersome and hard to maintain code to simulate enums and now want to simplify it. I need to get the name of the enum as a string such as can be done ...
Nate Lockwood's user avatar
2 votes
2 answers
98 views

Here is a simple program that overwrites an enum variable with another variant with associated data, and then needs a reference to that associated data afterward. (A more realistic example would have ...
jacobsa's user avatar
  • 7,817
1 vote
1 answer
89 views

I have a set of classes linked into an enum: #[derive(Default)] pub struct A { } #[derive(Default)] pub struct B { } #[derive(Default)] pub struct C { } enum Classes { A(A), B(B), C(C), ...
Alan Birtles's user avatar
  • 38.3k
167 votes
8 answers
274k views

To encapsulate a list of states I am using enum module: from enum import Enum class MyEnum(Enum): state1='state1' state2 = 'state2' state = MyEnum.state1 MyEnum['state1'] == state # here ...
sophros's user avatar
  • 17.3k

1
2 3 4 5
458