enums

C# prevent enum to int conversion

I have an enum that enumerates integer values returned from an external API for easier use in my code. But I don't necessarily know the integer values at compile time, so I have some code that hooks them up at program start and stores them in a Dictionary. I've defined some extension methods for conversion to/from the integer codes, bu...

Why do "Not all code paths return a value" with a Switch statement inside of an Enum?

I have the following code: public int Method(MyEnum myEnum) { switch (myEnum) { case MyEnum.Value1: return 1; case MyEnum.Value2: return 2; case MyEnum.Value3: return 3; } } public enum MyEnum { Value1, Value2, Value3 } And I get the error: "Not all code paths return a value". I...

Enum in Java. Advantages?

What are some advantages of making enum in Java similar to a class, rather than just a collection of constants as in C/C++? ...

Is there any c/c++ compiler that can warn (or give error) or enum conversion to int?

Cleaning up old c/c++ code that used hardcoded integer literals instead of enums, it is tedious to find places where the function-declaration has been properly refactored but not the body. e.g. enum important { little = 1, abit = 2, much = 3 }; void blah(int e) { // magic stuff here } void boing(int e) { ... } void guck(impor...

Should I store my Enums at database level or in the application logic (.NET)?

Hi, I have a table, lets call it Objects. It has a predefined set of records looking like this: ObjectId ObjectName 1 Salmon 2 Trout 3 Seabass 4 Shark Etc.. So, this I would like to implement somehow as an enum. But what's the best way, implement it in the database creating tables for it or in the app...

Persist an enum wrapped in an interface with hibernate?

I'm using the latest version of Hibernate with Java. I've got three enum types that are being used as property names, each of the three property names go with different objects. There are different sets of property names for each object. Each property name is stored in a map with it's respective property value object, the property value ...

How to write annotations using multiple enum types?

I'm attempting to write some annotations to help associatate test case methods with various metadata. My annotations so far include BugFix, UseCase, and Requirement. My end goal is to write an annotations processor to display which test cases are associated with individual bug fixes, use cases, and requirements. When I was just implem...

Using a table to provide enum values in MySQL??

Is there a way to map one of the the columns contents of a MySQL table to an enum on another table in MySQL? I thought this would be a no brainer, but there doesn't seem to be any info that I can find on the subject. Any advice or help on this matter would be cool and if it's not possible, does anyone know of an internal reason why it w...

Enum assigned value parse c#

Okay, for whatever reason I can't seem to figure this little problem out. I have the following enum: public enum EFeedType { TypeOne = 1, TypeTwo = 2 } Now, I am going to be getting the numeric value from a database. Well, I need to cast the int value from the DB to the enum type: EDIT: The database type is integer, so I do ...

C#: Is there a way to classify enums?

Given the following enum: public enum Position { Quarterback, Runningback, DefensiveEnd, Linebacker }; Is it possible to classify the named constants, such that I could mark 'Quarterback' and 'Runningback' as offensive positions and 'DefensiveEnd' and 'Linebacker' as defensive positions? ...

.Net Serialization, XmlDataReader, a SQL Database and the FlagsAttribute!

Giving a quick overview of my situation: I am working on an N-Tier app that relies a lot on serialization, objects interact with the database mainly in a serialized fashion, objects and collections are inserted, updated and read as XML from within stored procedures. For some of the smaller data classes I am simply using ExecuteNonQuery...

Java: Dynamic type casting using enums

Hi, I am trying to do something along the lines of: public void setContents(Object[] values) { ... //A. this works mRank = ((String)(values[Columns.RANK.index])); //B. doesn't work (entire line underlined by netbeans) mRank = (Columns.RANK.type.cast(values[Columns.RANK.inde...

Matlab 2009b & .NET

I am having all sort of trouble with [FlagsAttribute] enums in Matlab. It appears there is no way to pass a combination of values as a parameter to .NET. For example, BindingFlags.Public|BindingFlags.Instance, once you combine these together in Matlab they become of an internal type and cannot be cast back to BindingFlags. Things like ...

Objective-C, enumerators and custom setters - How to make it work?

I have an Application Delegate class with a enumeration which looks like this: typedef enum { Online = 3500, DoNotDisturb = 9500, Offline = 18500, Away = 15500, Busy = 6500, BeRightBack = 12500 } status; Additionally I have a property to set a value from the enumerator in my interface file: @interface MyAppDel...

Testing enum gives warning: comparison between pointer and integer

I am getting this warning: warning: comparison between pointer and integer when doing the following: if (menuItem.menuType == LinkExternal) MenuType is a custom enum defined as below: enum menuItemType { LinkInternal = 0, LinkExternal = 1, Image = 2, Movie = 3, MapQuery = 4 }; enum menuItemType *menuType;...

C# Getting the Type of a Public Variable based on an Enum value

I have a class that parses in data from a comma delimited text file. I have an enum for the fields to help me parse data in easier. The class that parses all the records in holds public variables for each field, and of course their variable types. I need to get the type of these variables based on the enum given. public enum DatabaseFie...

When to use enums, and when to replace them with a class with static members?

It recently occured to me that the following (sample) enumeration... enum Color { Red, Green, Yellow, Blue } ... could be replaced with a seemingly more type-safe class: struct Color // (edited: this was previously a class) { private Color() { } public static readonly Color Red = new Color(); p...

wcf deserialize enum as string

I'm trying to consume a RESTful web service using WCF. I have no control over the format of the web service, so I have to make a few workarounds here and there. One major problem I cannot seem to get around, however, is how to make WCF deserialize an enum as a string. This is my code (names changed, obviously): [DataContract] public en...

Multiple ways to define C# Enums with [Flags] attribute?

I understand how Enums work in C#, and I get what the Flags attribute brings to the table. I saw this question, here. Which recommends the first flavor, but doesn't provide any reason/justification for it. Is there a difference in the way in which these two are defined, is one better than the other? What are the advantages to using the...

How can I create an enum type in Perl?

I need to pass back a enum value in perl, how can I do this? pulling from this thread: http://stackoverflow.com/questions/473666/does-perl-have-an-enumeration-type use strict; use constant { HOME => 'home', WORK => 'work', MOBILE => 'mobile', }; my $phone_number->{type} = HOME; print "Enum: ".$phone_number->{type}."\n...