Questions tagged [enums]

1

votes
2

answer
389

Views

typescript does not recognize exported enum

I'm using TypeScript 2.5.3 and Angular 5. There is an enum declared in a separate file like this: export enum eUserType { Driver = 1, Passenger = 2, User = 3 } And import/use it in other ts file like so: import { eUserType } from '../CorrectFilePath/eUserType'; export class ViewsModule { newVariabl...
Rzassar
1

votes
0

answer
14

Views

json Enum serialization breakes kotlin null-safety

I use Kotlin data classes and GSON to deserialize JSON schemas, and implement default values to protect against null-objects in JSON. Also- JSON int enums map to Kotlin enum values using the @SerializedName annotation: data class Person(@SerializedName("name") val name: String = ", @SerializedName("...
Mardann
2

votes
2

answer
63

Views

How can I use enums in structopt in Rust?

I'd like to make StructOpt work with enums such that every time a user passes -d sunday it'd parsed as a Day::Sunday: #[macro_use] extern crate structopt; use std::path::PathBuf; use structopt::StructOpt; // My enum enum Day { Sunday, Monday } #[derive(Debug, StructOpt)] #[structopt(name = "example"...
H. Desane
0

votes
2

answer
28

Views

Best way to store Http Response in Enum

I was wondering what the best way was to store common action Http return types in an Enum. I am intending on using this towards my controllers. Any help is appreciated. public enum Types { BadResponse("Failed to load") NotFound() Ok() etc... }
Chris H.
1

votes
2

answer
614

Views

Enum conforming to protocol with stored property

I'm following the Swift Tour and they have this example of a protocol protocol ExampleProtocol { var simpleDescription: String { get } mutating func adjust() } Then the exercise is Write an enumeration that conforms to this protocol. If I let Xcode stub out the enum, it does this enum SimpleEnum: Ex...
Max
1

votes
0

answer
9

Views

Closure returning reference to Enum variant content

I have a function that accepts a reference to an enum, which I need to parse by matching the enum and reading its content. One of the variants of the enum (not in the simplified minimal working example below), may contain as value the type of the enum itself, therefore I may need to recursively call...
Nick
1

votes
1

answer
140

Views

How to use DataTrigger From Enum property?

So i have this Enum: public enum Status { Intermediate = 0, Valid, NotValid } My ViewModel: public class MyData { private Status _status; public Status Status { get { return _status; } set { _status= value; OnPropertyChanged(); } } My TextBox Style: So this Status property is changing and i verify...
falukky
1

votes
1

answer
63

Views

I can't package my program with Pyinstaller because I have enum34 installed, can't uninstall because a used module needs it. Any suggestions?

So I am trying to package a program I wrote for my job that allows people to add, update, delete the same row/columns over multiple spreadhseets (@ Smartsheets) at the same time. I am using Kivy, and the Smartsheet-Python-SDK When I go to package the app with PyInstaller, per Kivy's direction, I get...
Matthew Palumbo
1

votes
1

answer
62

Views

Where to place view controller related enum

Situation I have a Page View Controller with number of child view controllers. Each one of the child view controllers are slightly different. To make it easy to manage, I defined enum MyPageViewChild enum MyPageViewChild { case someName... case someName... case someName... case someName... case some...
Bigair
1

votes
1

answer
56

Views

How to avoid code duplication when comparing two enums' variants and their values?

I need to compare two serde_json::Values: enum Value { Null, Bool(bool), Number(Number), String(String), Array(Vec), Object(Map), } The comparison will return another enum: enum Diff { Equal, Different, NotFound, } I started writing the code structured as follow: fn compare(val1: &Value, val2: &Valu...
Nick
1

votes
2

answer
53

Views

Dynamically set INT value to Nullable enum property without explicit type cast

I have a method that populates a DataTable to simple DTO object. To simplify I'll use this example: public enum Gender : int { Male = 1, Female = 2 } public class Person { //... public Gender? MyGender { get; set; } } static void Main(string[] args) { int intValue = 2; // value from DB var o = new P...
zig
0

votes
0

answer
39

Views

Why does naming an enum value “IN” cause a syntax error?

I have a class with an enum for units of length. class LengthUnit { public: enum Value { IN, CM, FT }; static double convert(double value, Value from, Value to){ if (from == to) return value; return value * getScale(from)/getScale(to); } constexpr LengthUnit(Value value) : value(value) {} bool opera...
Django
1

votes
2

answer
1.9k

Views

global scope enum and namespace conflict

I have an ATL COM service and in the .IDL file, I've declared an enum like so: In Gourmet.idl typedef enum Food { Chocolate = 0, Doughnut, HotDog } Food; A header file is automatically generated, creating Gourmet_i.h. In another .CPP file (let's just call it Decadence.cpp) of the same ATL COM projec...
ykay
1

votes
3

answer
3.5k

Views

How to save enum class in a HashMap?

Let us say we have following enums: public enum AnimalImages { TIGER,BEAR,WOLF; } public enum CarImages { BMW,VW,AUDI; } Now I want to save these enum classes in a HashMap: Map>(); enumMap.put("AnimalImages",???????); What I should enter instead of the question marks?
Hakan Kiyar
1

votes
1

answer
1.3k

Views

How to use enum class without a scope

I need to use the enumerator of the enum class multiple times in one block of code and I would like to avoid the classical enum from C++03. enum class Color {RED, GREEN}; { Color::RED //this works RED; //how do I make this work (only for this block)? } I tried using using namespace Color; bu...
Slazer
1

votes
1

answer
188

Views

Swift 2 value extraction from Enum

Prior to Swift 2, I would often use enums with associated values and add functions to extract specific values, like so: public enum Maybe { case Unknown case Known(T) public var value: T? { switch self { case .Unknown: return nil case .Known(let value): return value } } } This would allow me to do...
Aaron Hayman
1

votes
2

answer
572

Views

Set property of enum type given by string

I got some enum's in my class, it's look like this one: public enum A { A1, A2 } public enum B { B1, B2 } Problem is when i try to read items from XML file (each field given by property name and property value - both string). Now i got my method which is setting value of single property (there is on...
Zachwiany
8

votes
3

answer
243

Views

C++17: still using enums as constants?

I am used to using enum as constants -- they're quick to write, can be placed in .h files, and work fine. enum {BOX_LEFT=10, BOX_TOP=50, BOX_WIDTH=100, BOX_HEIGHT=50}; enum {REASONS_I_LIKE_ENUM_AS_CONSTANTS = 3}; Is this no longer a good idea? I see good reasons to prefer enum class (conventional...
Topological Sort
1

votes
2

answer
92

Views

What does “negation of enumeration” mean?

I was reading some code and I came across: static_cast(!value); where value is a following enum: typedef enum PValue { Lo = 0b0, Hi } PValue; What's the result of !value when value = Lo?
Quest
0

votes
1

answer
32

Views

Get enum value by passing enum type dynamically C#

I am using enum type in my C# program. enum div {A = 09, I = 04, L = 02, G = 14, P = 03, S = 06, D = 06, H = 07, P = 17} I have an other variable which holds some text with one of these enum types and the value of this variable change dynamically. Like var temp = "A"; //example int value; //should...
Dinesh Inavolu
5

votes
3

answer
298

Views

Which enum values are undefined behavior in C++14, and why?

A footnote in the standard implies that any enum expression value is defined behavior; why does Clang's undefined behavior sanitizer flag out-of-range values? Consider the following program: enum A {B = 3, C = 7}; int main() { A d = static_cast(8); return d + B; } The output under the undefined beha...
jbapple
1

votes
1

answer
165

Views

Resolving Swift.h and Bridging-Header.h circular references involving enums

I have an Objective-C header that has to be used by a Swift class. However, this header has to use the Swift.h file for an enum declared in a Swift file. In other words, the setup is as follows: MPViewController.h #import "MyProject-Swift.h" @interface MPViewController: UIViewController @property (n...
peco
1

votes
1

answer
201

Views

Forward-declare ns_options in Objective-C

How to forward declare NS_OPTIONS in Objective-C? Related SO question for NS_ENUMS: Forward-declare enum in Objective-C Unanswered question on Apple Dev Forum: https://forums.developer.apple.com/thread/16305 typedef NS_OPTIONS(NSInteger, MSSOption) { MSSOptionNone = 0, MSSOptionName = 1
foobar
1

votes
1

answer
475

Views

How to use enum as index key type in typescript?

Consider following example. enum DialogType { Options, Help } class Dialog { test() : string { return ""; } } class Greeter { openDialogs: { [key in DialogType]: Dialog | undefined } = { 0: undefined, 1: undefined }; getDialog(t: DialogType) { return this.openDialogs[t]; } } const greeter = new Gre...
ironic
1

votes
2

answer
56

Views

How to deal with -Wreturn-type for switch over C++11 enum class?

If I have a function that returns based on switching over a enum class, gcc emits warning: control reaches end of non-void function [-Wreturn-type]. Example code: enum class Test { a, b, c } ; int foo(Test test) { switch (test) { case Test::a: return 0; case Test::b: return 1; case Test::c: return 2...
Peter
1

votes
2

answer
38

Views

Creating a type that takes enum argument

I am trying to create a reusable type utilizing the Record type. enum MyKeys { ALPHA = 'ALPHA', BETA = 'BETA', GAMMA = 'GAMMA', } interface MyValues { in: any[]; out: any[]; } type Case = Record; Ideally I can use Case instead of Record. Type 'T' does not satisfy the constraint 'string | number | s...
ThomasReggi
1

votes
1

answer
50

Views

Is it possible to instantiate a class which contains an injected enum

Is it possible using Microsoft's DI to inject an enum? I am getting the following exception when instantiating a class which contains a enum in the constructor. InvalidOperationException: Unable to resolve service for type DependencyInjectionWithEnum.Domain.Types.TestType while attempting to activa...
Ron Skufca
1

votes
2

answer
84

Views

Validate value is in Python Enum values

I've inherited code that looks something like this. class Clients(IntEnum): ALICE = 1 BOB = 2 PETER = 3 CHERYL = 4 LARRY = 5 if client_id == 1: client_info = find_info(Clients.ALICE.value) elif client_id == 2: client_info = find_info(Clients.BOB.value) elif client_id == 3: client_info = find_info(Cl...
Josh Friedlander
1

votes
1

answer
23

Views

Enumeration issue when using Flag attribute

I have below enumeration: [Flags] public enum ElementsTag { None, Surname, SecondSurname, Forenames, PersonalNumber, Birthday, Nationality, DocumentExpirationDate, DocumentNumber, Sex, CityOfBirth, ProvinceOfBirth, ParentsName, PlaceOfResidence, CityOfResidence, ProvinceOfResidence } So, when I am t...
user1624552
1

votes
3

answer
48

Views

Multiple enumerations

I was wondering if I could use different enumerations in the same file where one is already present? For this project I have elements which act as a genre for a number of books. I want to create different story's for the books and create a 2nd enum for them. enum element { ICE, FIRE, EARTH, WIND, N...
Guraiya
1

votes
2

answer
23

Views

C Compare enumerate with invalid value

I would like try to understand how is working the compilator when we compare an enumerate with invalid value, and what the program is doing during execution. I found strange source code during my work, and did not understand the behaviour of the program, which was not giving me the expected result....
GOoOGle
1

votes
1

answer
20

Views

MVC doesn't accept parameter as enum

I'm trying to pass a parameter from js via AJAX call to my MVC controller but it's interpreting it as null. Is their a way to fix this? AJAX call service.GetYearsByType = function (docType) { var response = $http({ method: 'GET', url: '/Budget/GetYearsByType/' + docType }); return response; } MVC pu...
klent
1

votes
1

answer
158

Views

Get a string that contains the integer representation of an enum value

string userTypeId = ((int)ERPSystemUserType.Basic).ToString(); public enum ERPSystemUserType { Basic = 20, Upgraded = 30 } if I use ToString(), return the enum type's string value, however I want to use the defined int value. Is there any attribute or way, I could use for return string by is number...
user2650480
12

votes
2

answer
855

Views

Why does the scoped enum support operator '<' by default?

Consider: enum class Number {one, two}; if (Number::one < Number::two) {} My understanding is that the scoped enum needs to be cased into the underlying type or integer, and then it can be applied to operator < > ==. But it looks like the code snippet above can work without any explicit overloading...
SSY
1

votes
1

answer
105

Views

Too many attributes on enum?

My system currently runs in differents environments. I got a Environment enum on my system, something like this public enum Environment { [UsePayPal(false)] [ServerInstallDir("InstallPathOnServer")] [IntegrationSystemURI("localhost/someFakeURI")] [UpdateSomeInfo(true)] [QueuePrefix("DEV")] [UseCache...
Rafael Mueller
1

votes
3

answer
86

Views

What would be an appropriate collection type for storing few elements?

Of the different collection types supported in Scala (lists, maps, hashmaps, set etc) what would be an appropriate collection type for implementing something that can be done by C code below typedef enum { GOOD BAD MAX_QUALITY } quality struct student_data s_data[MAX_QUALITY]; The collection size is...
Girish
1

votes
2

answer
251

Views

What is the best approach for validating a combination of values using ENUMS in Java?

I am validating the status of a record retrieved from the DB by defining an ENUM as below public enum RecordStatusEnum { CREATED("CREATED"), INSERTED("INSERTED"), FAILED("FAILED"); private String recordStatusValue; RecordStatusEnum (String status) { recordStatusValue= status; } public boolean isS...
user1583803
1

votes
2

answer
1.3k

Views

Marshalling nested struct from C# to C++ DLL

I am trying to call a function from C# to a .DLL written in Borland C++ whose signature is: extern "C" __declspec(dllexport) ls50errortype __stdcall Ls50P2Open(ls50p2apiconfiginfostruct &configinfo); The corresponding call in C#: [DllImport("C:\\Lumistar\\LDPS_8x\\Ls50P2_Dll.dll", EntryPoint = "Ls50...
MSumulong
1

votes
1

answer
196

Views

Using reflection inside enums but always getting NoSuchMethodException

I'm building a custom component for Talend Open Studio to access a source of data from an application (JIRA) that has a wrapper to get all its data. It exposes an API full of very volatile getters for all its data structure. Since Talend Open Studio supports primitive type only, i usually need to ch...
Gabriele B
1

votes
1

answer
3.5k

Views

No enum in generated code using JAXB

My enum class @XmlType @XmlEnum(Integer.class) public enum Error { @XmlEnumValue("1") ENUM_VALUE_1(1, "some string 1", "some string 1"), @XmlEnumValue("2") ENUM_VALUE_2(2, "some string 2", "some string 2"); private Error(int errorCode, String msgKey, String message) { this.errorCode = errorCode; th...
White Roses

View additional questions