Questions tagged [enums]

1

votes
1

answer
307

Views

Use string variables in typescript's enum

Is it possible in typescript to use string variables in enum? I can use strings in enum like this: enum AllDirections { TOP = 'top', BOTTOM = 'bottom', LEFT = 'left', RIGHT = 'right', } But this code: const top: string = 'top' const bottom: string = 'bottom' const left: string = 'left' const right:...
Anton
0

votes
2

answer
25

Views

How to get rawValue of enum using there sub function?

Enum that is defined like below. enum PurchaseTimeType: Int,CaseIterable { case ASAP, ThisMonth, NextMonth func id() -> Int { switch self { case .ASAP: return 1 case .ThisMonth: return 2 case .NextMonth: return 3 } } func title() -> String { switch self { case .ASAP: return 'ASAP' case .ThisMonth: r...
PinkeshGjr
1

votes
1

answer
66

Views

Conversion of numeric strings to enum in C#

Recently I've discovered that any string that contains only numeric characters can be converted to enum in C#. For example, imagine there is an enum defined as follows: public enum TestEnum { One = 1, Two = 2, Three = 3 }; I can perform a conversion of some random numeric string to TestEnum. TestEnu...
NamiraJV
1

votes
1

answer
50

Views

Can't overload i/o operators for private enum in namespace

I have a private enum in a class within a namespace. I'm trying to overload the I/O operators, but all I get is the compiler complaining about the Enum being private. The solution from this post did nothing to help me. Here is an isolated version of my problem. TestClass.h #include namespace Test {...
ABernitt
1

votes
4

answer
1.5k

Views

How to pass enum as method parameter?

The task is to write a simple method that can sort int array (in ascending or descending order - should be set as enum type parameter of this method). I have written the method itself and enum, but I have no idea how to set enum as method parameter:( Would be great to get any help from you, guys, c...
LAL
1

votes
2

answer
184

Views

Convert an enum to a list in Python

I have an enum that I define like this: def make_enum(**enums): return type('Enum', (), enums) an_enum = make_enum(first=1, second=2) At some later point I would like to check, if a value that I took as a parameter in a funciton is part of an_enum. Usually i would do it like this assert 1 in to_li...
User12547645
1

votes
2

answer
48

Views

C++ Getting neighbours of a cell in a grid, -1x throwing null exception when checked if != NULL

recently moved from C# to C++ so I'm new to pointers and references and so on. I've a pointer-to-pointer array declared like this enum Type { Void, DeepWater, Water, ... etc } Tile::Type** tiles; TileManager::TileManager(int width, int height) { this->tiles = new Tile::Type*[width]; for (int w = 0;...
Anthony
1

votes
1

answer
64

Views

using Map vs Enum

I need to keep a mapping which finds some properties given a String. For an example like below, I need to get possible colors for an animal given the description for that animal. I have 'An animal with four legs' - not 'CAT' - and need to find BROWN and GREY. Keeping this in an enum makes code more...
canan
1

votes
1

answer
58

Views

Is it possible to give out a warning when switch (enum) does not cover every enum value AT COMPILE C#

So I have public enum Type { Cat, Dog, Horse, } private void SomeFunc(Type type) { switch (type) { case Type.Cat: // ... break; case Type.Dog: // ... break; default: throw new System.Exception(); } } Say that at first we only have Cat and Dog. And we already wrote millions of funcs like SomeFunc tha...
h5nc
9

votes
2

answer
210

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

View additional questions