Questions tagged [enums]

1

votes
0

answer
6

Views

Creating an enum from its name not value

Given the enumeration enum NATO (:alpha, :bravo, :charlie, :delta); it's possible to easily set a variable by literally typing one of the names, or by passing one of the values to the enum object: my $a = alpha; my $b = NATO('B'); say $a; # ↪︎ alpha say $b; # ↪︎ bravo say $a.v...
guifa
1

votes
0

answer
108

Views

Default Enum Constructor Exception In Spring Boot

I have this Enum definition:: public enum PromoUsage { ONLINE, OFFLINE, ONLINE_AND_OFFLINE; } I have another class where i use the Enum like this:: @Embedded @Column(name='promoUsage', nullable=false) @NotNull @Enumerated(EnumType.STRING) private PromoUsage promoUsage; Now when i run my Spring Bo...
Eddy Freeman
1

votes
0

answer
130

Views

ModelState validation fails for dictionary where keys are enums

I have a model that has the following property: [JsonConverter(typeof(MapConvertor))] [IsValidSomeObject] public Dictionary SomeMap { get; set; } And I created the following custom ValidationAttribute class to validate it: public class IsValidSomeObjectAttribute : ValidationAttribute { protected ove...
Apha
1

votes
0

answer
338

Views

Serialize enum to string with RestSharpJsonNetSerializer [duplicate]

This question already has an answer here: Why serializing Version with JsonPropertyAttribute doesn't work? 1 answer parsing an enumeration in JSON.net 1 answer How to tell Json.Net globally to apply the StringEnumConverter to all enums 5 answers I have my RestSharpJsonNetSerializer class below. I...
Razkar
1

votes
2

answer
157

Views

Swift: Undeclared Variable with Multiple Type Options

I'm learning swift through Apple's App Development book. There is a project for designing a Favorite Athlete App to view, add and edit athletes. I'm wondering if there is a way to have a variable in a struct/class that is of a type that is dependent on the literal of another variable.... Ok, so this...
Average_Pickle
1

votes
1

answer
182

Views

'Type is unsupported' error when trying to save Enum in DynamoDb

I have the below class that I have decorated with DynamoDb attributes: [DynamoDBTable('Orders')] public class OrderDynamoModel { [DynamoDBHashKey] public int OrderId { get; set; } [DynamoDBProperty] public DateTime DateTimeUtc { get; set; } [DynamoDBProperty] public int TId { get; set; } [DynamoDBPr...
Shaun Ros
1

votes
1

answer
103

Views

why the size of the C++ class with enumerations declared is 1?

class test { public: enum t_number { ZERO, ONE }; enum t_test { TWO, THREE }; }; Why the size of the above class is 1 and not 8? And when I do this in main() cout
Vignesh Rajendran
1

votes
0

answer
40

Views

Trying to use void pointers and random generate an enum array with distinct elements (C++)

I tried to use void pointers and random generate enum array with no repeated elements. But It still have duplicated elements. Which part of my codes is wrong? P.S I haven't learnt vectors, shuffle or iota, thus not allow to use it. This is my enum enum Fruit {Durian, Papaya, Apple, Orange, Mango, Ja...
skyzhuzhu
1

votes
0

answer
45

Views

Why do Static Methods & Enumerations have unexpected behavior in Xamarin Forms? Objects Passed to Static Methods become null & enums are stored as int

I have been using C#/.NET/Visual Studio since 2000, but I just started working with Xamarin Forms recently. It's a pretty great platform, however I have run across a couple of issues that I cannot figure out. (I'm using Visual Studio 2017 Community). I have been researching this behavior extensively...
John
1

votes
0

answer
336

Views

Enum Localization generic approach

Enum public enum EmployeeStatus { ACTIVE, IN_ACTIVE } In callers scattered all over the application whicg get and set the enum like below. Here are examples Caller_1 if(employee.getStatus() == EmployeeStatus.STATUS.SUBMITTED) { } Caller_2 employee.setStatus(EmployeeStatus.STATUS.SUBMITTED) Problem...
user3198603
1

votes
0

answer
60

Views

Multi-Line comments Invalid inside Enum

Situation: I noticed today, when commenting my code, that a single line comment inside of an Enum is ok, but a multi-line comment, with a line break, throws the error: Invalid inside Enum For example, the following works: Option Explicit Public Enum testing 'My comment text Value1 = 1 Value2 = 2...
QHarr
1

votes
0

answer
140

Views

Rails5.0.2 enum handling invalid values

I have a Work model that includes a status enum type enum status: { beginning: 0, middle: 1, end: 2 } Upon creating a new Work record, there could be a scenario where the status value being passed is something like finished. In that case, I am getting `ArgumentError: 'finished' is not a valid statu...
Fabien Bessez
1

votes
1

answer
289

Views

Override typescript enum descriptions

I have the following enum generated somewhere outside of my app: enum Colors { Red = 'RED', Green = 'GREEN', Blue = 'BLUE', } This enum is used as a type for generated interface property interface MyObject { objectName: string, objectColor: Colors } Is it possible to override enum string values so t...
elm
1

votes
1

answer
45

Views

Disable specified item of bound combobox

I have the following code in my test application. XAML file: IsItemEnabled ViewModel using System.ComponentModel; using System.Runtime.CompilerServices; using TestWpfApplication.Annotations; namespace TestWpfApplication { public class MainWindowViewModel : INotifyPropertyChanged { private bool _is...
user3525444
1

votes
1

answer
71

Views

How to display an enum with duplicate values in a .NET PropertyGrid?

I have an enum that contains duplicate values. For example: public enum DataVals : byte { C1_Route1to2 = 1, C4_Route3to5 = 1, C6_Route1to2 = 2, C7_Route3to5 = 2 } The values C# are just internal values within my application. Depending on which route is selected by the user, route is another propert...
pavuxun
1

votes
1

answer
33

Views

How i can compare to which nesting enum associated my value

this is my code public enum Key { enum A: String { case x } enum B: String { case y } enum C: String { case z } } Now I need to compare to which nesting enum the argument belongs, it is possible something like this? func readString(key: Key) { switch key { case .A: //do smth default: break } }
1

votes
0

answer
40

Views

How to create a upgrade system for a game (Mostly using enum)

Hello everyone and have a nice day. I'm trying to create a system similar to Asssassin's Creed Syndicate Upgrade system as you can see in the following picture which i took from google. https://i.stack.imgur.com/30prp.jpg Basically, you can take a upgrade, starting from top to bottom and everytime y...
Evie Frye
1

votes
1

answer
631

Views

How to resolve The datum is not an example of schema (Avro::IO::AvroTypeError)

I am a newbie to Avro with Ruby and basically to programming. While i was performing some basic stuff on Avro with ruby, I see some issues with the schema. Below is the code. require 'rubygems' require 'avro' require 'mysql2' require 'json' require 'multi_json' # setup mysql db = Mysql2::Client....
user265629
1

votes
0

answer
32

Views

An overloaded setter not called for assigning a string to an enum field

Working with an application which uses a home-grown entity framework which comes as a referenced DLL (no source code), I have to access SQL data using its methods, like: var allMyClasses = EF.ReadTable('select a, b, c from myTable') This call returns IList. Whenever MyClass has a string member, whic...
ajeh
1

votes
1

answer
32

Views

Accessing enums using an identifier prefix

I've been doing a lot of C# programming lately and now going back to C++ I am missing a few language features, though I am wondering if it would be possible to do something similar. In C# elements of an enum are accessed using the name of the enum as a prefix, like this… enum TypeA { one, two, thr...
Striding Dragon
1

votes
2

answer
45

Views

How can I cleanly validate and cast to an enum that is nonsequential? [duplicate]

This question already has an answer here: How to check if enum value is valid? 8 answers Consider the following code: //Note that the enum is nonsequential. I don't have control of //this enum so I cannot change it to be sequential enum class Animal { DOG = 0, CAT = 1, LLAMA = 20, ALPACA = 21, }; /...
JD Reese
1

votes
2

answer
82

Views

How to sort my list object based on order of Enum values

I have an enum: public enum EnumProductConfig { Color, Fold, Edge, Hem, Lift, Tapes, Control, Clips, Pull, Val } The order of above values in enum is not alphabatical which is totally ok with me. Now, I have a list with one of the property of type EnumProductConfig. I want to sort my list based...
Shiva Wahi
1

votes
1

answer
234

Views

How to get the enum value instead of enum name in OData v4?

I have an enum that looks like this: enum Color : byte { Transparent, White, Black } When I request the values from my Entity I get the results as strings, not integers, example: { 'Color': 'White' } Is there any way to make OData return the value instead of the name of the value? I'm using Microsof...
Emerson Jair
1

votes
0

answer
197

Views

Java - NullPointerException for Enum.values() in WAR archive

I've got an Enum class that stores the name and some relevant numbers for 10 different materials. In my HTML page I want to select one material via a drop down. Therefore I iterate over them via JSTL. I used to have a scriplet for that but I replaced it now. This is my code: Servlet: protected void...
Merha
1

votes
1

answer
328

Views

Passing a List to Enum as parameter

public enum Character { LAURA('Laura', Item.SANDWICH,0.0f), SALLY('Sally', Item.CRISPS,0.1f), ANDY('Andy', Item.DRINK,0.2f), ALEX('Alex', null,0.3f); private String description; private Item item; private float probability; ArrayList itemsLaura = new ArrayList(); ArrayList itemsSally = new ArrayLis...
super95
1

votes
1

answer
36

Views

How do I switch on an Enum in Swift, depending on the input I provide? [closed]

I have created the below switch statement to return a Double value depending on what string I input in weightType. I would like to it with an Enum instead, so that it's more flexible. I though it was an easy change but I have tried all kinds of things and I can't make it work. Can someone please hel...
mlynnerup
1

votes
2

answer
43

Views

Be able to call a function from an enum? c#

Basically, I wish to have an enum, where each constant is referencing a function (more of an procedure however since it doesn't return anything) . enum Example {first_function, second_function, third_function}; void first_function (){ } ... you get the hang of it Is there a method where I can call s...
karr7224
1

votes
0

answer
26

Views

How to get all records with specific enum in a simple_enum rails 3

spotlight.rb as_enum :media_type, :image => 0,:video => 1 When I do Spotlight.last.media_type return nil. But when I do Spotlight.last.image? it returns true 2nd issue is that it not returns list of all records when I do Spotlight.images Spotlight.videos
Haseeb Ahmad
1

votes
0

answer
77

Views

How do I make use of the `self` data in a method implemented on an enum? [duplicate]

This question already has an answer here: How to match over self in an enum? 1 answer Why can't `Self` be used to refer to an enum's variant in a method body? 4 answers I am working through the docs on enums and I'm at implementing a method on an enum. How do I make use of the self info passed in...
seamus
1

votes
2

answer
61

Views

Alternative to static overriding in java

I've been struggling with it for a while now. I want to define a finite set of types, some of which would be subtypes to others, where each type is defined by values of its properties. The types would then be used to access their properties and also by a factory method to create instances of them. I...
svatcher
1

votes
2

answer
200

Views

Hibernate fetching deleted java enum types from db

I have an Enum class which has some values. We've decided to remove one of these values and its all implementation from the code. We dont want to delete any records from DB. My Enum class is something like this: public enum CourseType { VIDEO('CourseType.VIDEO'), PDF('CourseType.PDF'), QUIZ('Course...
theYoungPadawan
1

votes
1

answer
65

Views

How to disable indentation of enum methods?

Given: public enum Test { ONE { public String toString() { return 'foo'; } }, TWO { public String toString() { return 'bar'; } } } IntelliJ IDEA 2018.1 is indenting the braces containing the methods as follows: public enum Test { ONE { public String toString() { return 'foo'; } }, TWO { public Strin...
Gili
1

votes
0

answer
41

Views

determine function out type based on input Enum c#

I have 3rd party DLL which have an enum with 70 values and a function that based on that get that enum and set the return value but my problem that the this functions 19 overloads on the out value if there a clean way to do it(not using if-else, or create a huge dictionary) here's my sample code (i...
styx
1

votes
0

answer
22

Views

Adding data to ENUM field via form in sql

I currently have a form where values are submitted to add data to my table. I have a field 'property_id' which is an ENUM. Every time I try to submit the field I get the error message: Fatal error: Uncaught mysqli_sql_exception: Data truncated for column 'property_id' at row 1 in ... Is there any w...
canjess
1

votes
0

answer
275

Views

Find usages for enums via Ctrl + left in IntelliJ

In IntelliJ I can very easily find usages of an enum constant by Ctrl + left click on an enum constant. However, if the enum implements a constructor, I'm going directly to that constructor instead. I know I can also search for usages with Alt + F7 but is it possible to always do that on Ctrl + left...
Sebastian
1

votes
1

answer
330

Views

Import Enum File Imcompability with Python 2.7

I am having issues running a Python file that uses 'import enum', giving me this issue: Traceback (most recent call last): File 'lowest_common_ancestor.py', line 4, in from test_framework import generic_test, test_utils File '/Users/linh/Documents/EPIJudge/epi_judge_python/test_framework/generic_te...
Linh
1

votes
1

answer
713

Views

How to filter list elements from enum in typescript?

I am working on Angular 2 with Typescript, and I have a scenario where I have to filter elements from a list after comparing with enum. Like - let products: Array = [A, B, C, D, E, F]; below is my enum- export const enum ProductType { A= 0, B= 1, C= 2 } Now I want to return a list with below...
user3848036
1

votes
1

answer
128

Views

Representing complex objects in a Python enum

I am working with a graph-based framework that consists of several types of nodes and relations. Each of these types has some meta-properties that I would like to be able to access easily. To represent these types, I figured that an enum would be the way to go. I'm still relatively new to Python, b...
thijsfranck
1

votes
1

answer
119

Views

Python pass enum as the constructor parameter [duplicate]

This question already has an answer here: In Python how can I access “static” class variables within class methods 5 answers Does someone know, how can I use an Enum as class constructor parameter? I have created such class: class Coin(Cash, Enum): onePenny = 1 twoPens = 2 fivePens = 5 ones = 0...
wkondrat
1

votes
0

answer
266

Views

Sequelize - Node Js - enum and Integer field Search option

In Sequelize - ORM Node JS when using the enum and integer field while searching particular element with like operator gives error as: No operator matches the given name and argument type(s). You might need to add explicit type casts. How did i need to type cast for integer and enum field ? My wh...
Sheema

View additional questions