enums

Enum array from string with delimiter

Hi, I want to give something back - found lots of answers here! The problem is to convert a string (eg. "AA_BB_CC") into an array of enums using a specified enum class. public static <T extends Enum<T>> T[] getEnumArrayFromString(final Class<T> enumType, final String codeStr, ...

Why does unboxing enums yield odd results?

Consider the following:: Object box = 5; int @int = (int)box; // int = 5 int? nullableInt = box as int?; // nullableInt = 5; StringComparison @enum = (StringComparison)box; // enum = OrdinalIgnoreCase StringComparison? nullableEnum = box as StringComparison?; // nullableEnum = null. 2 things:: Why can I unbox to StringComparison? I...

Typedef enum setting and accessing

Hello there! I have this before the interface declaration in my MainView.h header. typedef enum { UNKNOWN, CLEAR, NIGHT_CLEAR, CLOUDY, NIGHT_CLOUDY } Weather; Then I declared it like this: Weather weather; Then made an accessor: @property Weather weather; And synthesized it. My question is, how can I use this in a different...

Enum Intellisense Display Attribute??

I want to do this: enum Foo { [Display="Item One"] ItemOne, } So that Intellisense will display it like in the attribute instead of the actual name. I know it's possible, I've seen it before. ...

Is an Extension Method the only way to add a function to an Enum?

I have a Direction Enum: Public Enum Direction Left Right Top Bottom End Enum And Sometimes I need to get the inverse, so it seems nice to write: SomeDirection.Inverse() But I can't put a method on an enum! However, I can add an Extension Method (VS2008+) to it. In VB, Extension Methods must be inside Modules. I r...

C++ compilation error enum "does not name a type"

Hello, The following code: foo.h #include "bar.h" class foo{ public: enum my_enum_type { ONE, TWO, THREE }; foo(); ~foo() {} }; foo.cpp foo::foo() { int i = bar::MY_DEFINE; } bar.h #include "foo.h" class bar{ public: static const int MY_DEFINE = 10; foo::my_enum_type var; bar() {}; ~bar() {}; }; Mak...

Custom Attributes and enumerators

Hey There I have an enum: public enum Navigation { Top = 0, Left = 2, Footer = 3 } And i have a controller action: public ActionResult Quotes() { return View(); } I would like to be able to decorate my action as follow: [Navigation.Top] public ActionResult Quotes() { return View(); } Any idea how this could ...

Call methods on class templatized over enum

Given the following code: enum Fruits{ eApple, eBanana }; template<> struct SomeFruit< eApple > { void eatIt() { // eat an apple }; }; template<> struct SomeFruit< eBanana > { void eatIt() { // eat a banana }; }; Is there a way to call the explicitly specialized eatIt(), for each of Fruits, without having to make each call m...

Application crashes after trying to set typedef enum

Hello there! I had asked a question similar to this before, but I have a new problem with it so I've reposted part of the question. I have this before the interface declaration in my MainView.h header. typedef enum { UNKNOWN, CLEAR, NIGHT_CLEAR, CLOUDY, NIGHT_CLOUDY } Weather; Then I declared it (in my MainView) like this: Weather...

How do return an enum in a typedef of function pointer?

#include <stdio.h> enum bool { true, false }; typedef bool (*compare_fun) (int, int); I get an error when I enter the above code. How do I make a function pointer that needs to return a boolean? ...

Java - Enum with array field

Hey, I want to store a list names and individual nicknames for each name as an Enum in Java. The number of nicknames will not vary. The purpose is to be able to get a full name from a nickname. Currently I have implemented this like so: public enum Names { ELIZABETH(new String[] {"Liz","Bet"}), ... ; private Strin...

Is there any harm in having many enum values? (many >= 1000)

I have a large list of error messages that my biz code can return based on what's entered. The list may end up with more than a thousand. I'd like to just enum these all out, using the [Description("")] attribute to record the friendly message. Something like: public enum ErrorMessage { [Description("A first name is required for...