enums

Find out if element is in enum

is there an easy way in C to figure out if an enumeration contains a certain element? ...

How to return a Enum value from a string?

I'm trying to return a strongly typed Enumeration value from a string. I'm sure there is a better way to do this. This just seems like way too much code for a simple thing like this: public static DeviceType DefaultDeviceType { get { var deviceTypeString = GetSetting("DefaultDeviceType"); ...

Do I always have to cast enum or am I doing something wrong?

if I have a very simple enum of ints like this. enum alignment { left, center, right} Where I want the datatype to be an int, which I understand is the default, and the values to be left = 0, center = 1, right = 2. But if I try and use a value from the enum like header.Alignment = alignment.center; I am told that I need to cast ...

[java] Number for each enum item?

Is it possible to define something like this in java? C# code: public enum Character { A = 1, B = 2, C = 4, D = 8 } ... Character ch = /* from user */ if(ch & Character.A) { // some operation... } for example if ch set to Character.B then result of if will be false: ch = 00000000 00000000 00000000 0000001...

JPA @Enumerated Error

Hi, I have a Entity with a field which I want to be an Enum. @Column(name = "TEMPRATURE_ZONE") @Enumerated(STRING) private TemperatureRegime tempratureZone; The Enum is defined as follows: public enum TemperatureRegime { AMBIENT, CHILL } The data in my table for this field is always "AMBIENT" or "CHILL" yet when I do a fi...

Comparing enumType values with int.

Hello. I'm developing a C# application and I have the following enum: public enum TourismItemType : int { Destination = 1, PointOfInterest = 2, Content = 3 } And I also have a int variable, and I want to check that variable to know it is equal to TourismItemType.Destination, like this: int tourismType; if (int.TryPars...

Javascript enum within an enum

I have the following "Enum" in javascript to indicate the state of my application: var State = { STATE_A: 0, STATE_B: 1, STATE_C: 2 //... } Now, I want each state to have a "sub-state". So for example, STATE_B could be in STATE_B1 or STATE_B2 ... What would be the best way to structure this? Would I somehow nest an "enum...

Enumerations: Why? When?

I am an almost-graduating computer science student, and throughout my coding career, I've found very few instances where enumerations, except for canonical cases such as representing the faces of a standard deck of cards, are used. Do you know of any clever ways that enums are used in everyday coding? Why are enumerations so important ...

Sensible pattern for ValidationError class in C#

I am about to implement a class to represent a validation error. The class would definitely contain a string value called Message, which is a default message to display to a user. I also need a way to represent what the validation error is to the programmer. The idea is that there should be an easy way to determine if a particular valida...

Flags Enum attribute

What is the point of the [Flags] attribute you can bit test without it? ...

Business logic in Enums?

Is it considered good practice to put any type of business logic in Enums? Not really intense logic, but more of like convenience utility methods. For example: public enum OrderStatus { OPEN, OPEN_WITH_RESTRICTIONS, OPEN_TEMPORARY, CLOSED; public static boolean isOpenStatus(OrderStatus sts) { return sts == OPEN || sts == OP...

Making C functions available to php

I have a C dll containing functions and enumerations I want to make accessible from php. How can I do it? ...

Design problem with respect to inheriting enums

Hi, I am building a framework where I need error checking for classes. I cannot use exceptions (not allowed). I decided to make a class that is inherited by all the classes that need error reports which has functions such as ReportError() [for the class itself] and GetError() [to get the last error - used by the caller] as well as funct...

Using Multiple NSUInteger enums as a parameter to a method.

Hi, I'm trying to make a method with a similar format to the setAutoresizingMask: method of NSView. I want to have someone be able to specify multiple values that i declared in my enum (NSHeightSizable | NSWidthSizable) like in autoresizing mask. How can I do this? ...

Listing values of unknown enum

Say we have a Class object. Name it cls. Now cls.isEnum() returns true What a joy!!! Could I please have the values listed to me? (one sugar, no milk) ...

Hibernate Enum mapping using annotaions

I have an existing database that I am now connecting to using hibernate. I cannot change the data in it at the moment and have everything working apart from a single column. I have a status column that has the values: new mailed in out And the column is mapped as follows: @Column(name = "STATUS", nullable = false, length = 50) @En...

Typesafe enum in Java

Hello, Not sure whether the title is misleading, but requirement is below. I need to use a string value as input to a custom annotation. When use an enum value, the IDE gives java attribute value must be constant. @test("test") // works @test(Const.myEnum.test.toString()) //java attribute value must be constant I read abou...

Mapping collection of enum in NHibernate.

Hi all! I have a class with collection of enums: Class1.cs public enum Language { Serbian = 1, Croatian, Ukrainian, } public class Class1 { private IList<Language> m_languages = new List<Language>(); public virtual IList<Language> Languages { get { return m_languages; } set { m_languages = val...

Special members in enum: All and None

Possible Duplicate: How to use Enum with aditional options (All, None) Somewhat subjective. I have an enum public enum Faction { Aliance, Horde } as we all know code closely modeling business domain it is applied is "always better". In a given domain there are two factions, and these two factions are enumerated in ...

Can an ASP.NET MVC2 site have an optional enum route parameter? If so, can we default that value if not provided?

Hi folks, can I have a route like... routes.MapRoute( "Boundaries-Show", "Boundaries", new { controller = "Boundaries", action = "Show", locationType = UrlParameter.Optional }); Where the action method is... [HttpGet] public ActionResult Show(int? aaa, int? bbb, LocationType locati...