enums

is there a way to check if int is legal enum in C#

I've read a few SO posts and it seems most basic operation is missing. CAN IT BE?? public enum LoggingLevel { Off = 0, Error = 1, Warning = 2, Info = 3, Debug = 4, Trace = 5 }; if (s == "LogLevel") { _log.LogLevel = (LoggingLevel)Convert.ToInt32("78"); _log.LogLevel = (LoggingLevel)Enum.Parse(typeof(Lo...

NHibernate MySQL Enum

I am trying to access the "MYSQL" database tables to create a GUI for adding users and privileges. Doing this, I have run into my first NHibernate problem. How do i map MySQL Enum's to a C# Boolean? Or if not possible then to at least a Enum? The database fields are delcared as enum('N', 'Y') These are all of the privilege fields i...

Boost::Container::Vector with Enum Template Argument - Not Legal Base Class

Hi, I'm using Visual Studio 2008 with the Boost v1.42.0 library. If I use an enum as the template argument, I get a compile error when adding a value using push_back(). The compiler error is: 'T': is not a legal base class and the location of the error is move.hpp line 79. #include <boost/interprocess/containers/vector.hpp> class Te...

Use of enums in C?

Hi all, Is there anyway by which we can copy one enum to another one?For eg: enum Element4_Range{a4=1,b4,c4,d4}; enum Element3_Range{a3=1,b3,c3}; enum Element3_Range Myarr3[10]; enum Element4_Range Myarr4[10]; enum Element3_Range MyFunc(Element4_Range); main() { MyFunc(Myarr4); ...

Enum as Generic Constraint: What's the Reason Microsoft Didn't Want to Implement It?

I realize that enum cannot be used as a generic constraint, and Microsoft has declined to fix this bug. Any reason why? ...

Which is better Java programming practice: stacking enums and enum constructors, or subclassing?

Hi folks, Given a finite number of items which differ in kind, is it better to represent them with stacked enums and enum constructors, or to subclass them? Or is there a better approach altogether? To give you some context, in my small RPG program (which ironically is supposed to be simple), a character has different kinds of items in...

Constraining enum value in method parameter

enum Fruit { Banana, Orange, Strawberry ... ... // etc, very long enum } PeelFruit(Fruit.Orange); PeelFruit(Fruit.Banana); PeelFruit(Fruit.Strawberry); // huh? can't peel strawberries! Sorry for the lame example, but hopefully you get the idea. Is there a way to constrain the enum values that PeelFruit will ac...

WCF Serialising Enums using Message Contracts

I have some web services that use Message contracts. It's probably worth mentioning that for these services, I cannot shift to Data contracts... One of my types specifies a property whose type happens to be an enum: [SerializableAttribute()] [MessageContract(IsWrapped = false)] [KnownType(typeof(RiskTypeCode))] public partial class Ris...

How to convert between Enums where values share the same names ?

Hi, if I want to convert between two Enum types, the values of which, I hope, have the same names, is there a neat way, or do I have to do it like this...? enum colours_a { red, blue, green } enum colours_b { yellow, red, blue, green } static void Main(string[] args) { colours_a a = colours_a.red; colours_b b; //b = a; ...

Enum mapping and criteria

Hi, I have two entities: "Parent" & "Child" Child is mapped in Parent like this: Code: <many-to-one name="child" class="org.demo.Child" update="false" insert="false" embed-xml="false" node="chd/@id" > <column name="CHILD_ID" precision="10" scale="0" not-null="true" /> </many-to-one> and Child has an Enum type mapped ...

How do I store and switch over preferences?

I want to store some user preferences Would Enum be a good datastructure to store them? If so, how do I do it? This is the final usage of the datastructure. main(){ int my_val = PREFERENCES.BLACK; switch(PREFERENCES){ case BLACK: ... } ...

JCombobox containing enum values inside a table

Hello, I have a class containing Enum with values. (names) In other class I would like to enter inside a table a cell type of JCombobox that will use these enums values. my problem is to combain between string values and the enum. for example the enum class: enum item_Type {entree, main_Meal, Dessert, Drink} for example th...

Why would an Enum implement an Interface?

I just found out that Java allows enums to implement an interface. What would be a good use case for that? ...

Is it possible to load items from an Enum to a ComboBox in .NET 3.5?

Thanks for the info! ...

what is the advantage of using negative enums

In the kaleidoscope parser / AST example at LLVM, the enum is given all negative values. Why the minus sign ? enum Token { tok_eof = -1, // commands tok_def = -2, tok_extern = -3, // primary tok_identifier = -4, tok_number = -5 }; ...

Enum : get the keys list

Hello, I'm not a java developer. But I'm currently taking a look at Android applications development so I'm doing a bit of nostalgy, doing some java again after not touching it for three years. I'm looking forward using the "google-api-translate-java" library. In which there is a Language class. It's an enum allowing to provide the lan...

how to use JComboBox using Enum in Dialog Box

Hi, I define enums: enum itemType {First, Second, Third}; public class Item { private itemType enmItemType; ... } How do I use it inside Dialog box using JComboBox? Means, inside the dialog box, the user will have combo box with (First, Secon...

Extending Functionality in an Enum

Consider I have an enum, which I have coded today. What are the possible ways to extend its functionality, or perhaps add more variables to it, on a later date? Will partial enums do the trick? ...

Checking if Type instance is a nullable enum in C#

How do i check if a Type is a nullable enum in C# something like Type t = GetMyType(); bool isEnum = t.IsEnum; //Type member bool isNullableEnum = t.IsNullableEnum(); How to implement this extension method? ...

Is there a way to make `enum` type to be unsigned?

Is there a way to make enum type to be unsigned? The following code gives me a warning about signed/unsigned comparison. enum EEE { X1 = 1 }; int main() { size_t x = 2; EEE t = X1; if ( t < x ) std::cout << "ok" << std::endl; return 0; } I've tried to force compiler to use unsigned underlying type for enum with t...