enums

How do you bind the TextWrapping property of a TextBox to the IsChecked value of a MenuItem?

The TextWrapping property of the TextBox has three possible values: Wrap NoWrap WrapWithOverflow I would like to bind to the IsChecked property of a MenuItem. If the MenuItem is checked, I want to set the TextWrapping property of a TextBox to Wrap. If the MenuItem is not checked, I want to set the TextWrapping property of the TextB...

Nested Java enum definition - does declaring as static make a difference?

I have an interface - here's a nicely contrived version as an example: public interface Particle { enum Charge { POSITIVE, NEGATIVE } Charge getCharge(); double getMass(); etc... } Is there any difference in how implementations of this would behave if I defined the Charge enum as static - i.e. does this...

How to persist an enum using NHibernate

Hi, Is there a way to persist an enum to the DB using NHibernate? That is have a table of both the code and the name of each value in the enum. I want to keep the enum without an entity, but still have a foreign key (the int representation of the enum) from all other referencing entities to the enum's table. ...

How Does MySQL Store Enums?

If I have a table like this: CREATE TABLE sizes ( name ENUM('small', 'medium', 'large') ); Is MySQL going to store those strings in every row, or internally will it use something smaller like integers to know which enum value to refer to? I want to use an enum in a table but I'm worried if it's as wasteful as storing a string in ...

can we define implicit conversions of enums in c#?

Is it possible to define an implicit conversion of enums in c#? something that could achieve this? public enum MyEnum { one = 1, two = 2 } MyEnum number = MyEnum.one; long i = number; Edit: If not, why not!! :) ...

C++: Iterate through an enum

I just noticed that you can not use standard math operators on an enum such as ++ or += So what is the best way to iterate through all of the values in a C++ enum? ...

Does SQL Server 2005 have an equivalent to MySql's ENUM data type?

I'm working on a project and I want to store some easily enumerated information in a table. MySql's enum data type does exactly what I want: http://dev.mysql.com/doc/refman/5.0/en/enum.html . Is there an equivalent in SQL Server 2005? I know I could store the possible values in a type table with a key, but I'd rather not have to link ...

In C++: Is it possible to have a named enum be continued in a different file?

For example: Base class header file has: enum FOO { FOO_A, FOO_B, FOO_C, FOO_USERSTART }; Then the derived class has: enum FOO { FOO_USERA=FOO_USERSTART FOO_USERB, FOO_USERC }; Just to be clear on my usage it is for having an event handler where the base class has events and then derived classes can add events. The derived classes...

Enumeration extension methods

In vs2008, is it possible to write an extension methods which would apply to any enumeration. I know you can write extension methods against a specific enumeration, but I want to be able to every enumeration using a single extension method. Is this possible? ...

Java: `enum` vs `String` as Parameters

I've been reading through the details of the System libraries set and get methods yet the parameters are usually Strings. Would you consider the use of String as parameters bad practise since the inclusion of enum? A better alternative at minimum might be public final String, No? ...

Array as the options for a switch statment

I remember from way back at university using a switch with 'binary search' or 'binary switch'. Something like that, My google foo is broken today. Anyway it goes down like this: You define an array of possible options (Strings usually), some magic happens, and those options in the array become the cases in the switch happens. I do rememb...

Enums in JavaScript?

What is the preferred syntax for defining enums in JavaScript? Something like: my.namespace.ColorEnum = { RED : 0, GREEN : 1, BLUE : 2 } // later on if(currentColor == my.namespace.ColorEnum.RED) { // whatever } Or is there a more preferable idiom? ...

How to avoid dependencies between Enum values in code and corresponding values in a database?

I have a number of user permissions that are tested throughout my ASP.NET application. These permission values are referenced in an Enum so that I can conveniently test permissions like so: btnCreate.Enabled = PermissionManager.TestPermission(Permission.AllowCreate); However, I also have these permissions stored in the database becau...

What is the best way to get an integer into an enum?

Criteria: Performance, Performance, Performance. I need a way to convert a uint, int, etc into it's enum equivalent. What's the fastest way I can do that using C#? ...

Design question with Enums to model Type relationships

In designing a class for customer for example would it make sense to use an Enum for CustomerType? ...

Can I compare MySQL enums?

I have an enumeration: ENUM( 'alpha', 'beta', 'gamma', 'delta', 'omega' ) If I sort my table by this column I get them in the correct order defined above. However, I can't find a way to select a subset of these, e.g. everything before delta. Using WHERE status < 'delta' only returns alpha and beta, not gamma. It seems MySQL uses a stri...

Get the Enum<T> value Description

Hi there, I have my enumHelper class that contains these: public static IList<T> GetValues() { IList<T> list = new List<T>(); foreach (object value in Enum.GetValues(typeof(T))) { list.Add((T)value); } return list; } and public static string Description(Enum value) { Attribute DescAttribute = LMIGHelper.GetAttribute(v...

c++ enum to unsigned int comparison

I found this in the code I'm working on at the moment and thought it was the cause of some problems I'm having. In a header somewhere: enum SpecificIndexes{ //snip INVALID_INDEX = -1 }; Then later - initialization: nextIndex = INVALID_INDEX; and use if(nextIndex != INVALID_INDEX) { //do stuff } Debugging the code, t...

Enum String Name from Value

I have an enum construct like this: public enum EnumDisplayStatus { None=1, Visible=2, Hidden=3, MarkedForDeletion=4 } In my database, the enumerations are referenced by value. My question is, how can i turn the number representation of the enum, back to the string name. for example, given '2' the result should be ...

How do I store an enum value in a Windows Forms settings file?

I'm using Windows Forms and VS2008. I want to store an enum value in my application's settings file. The settings editor in VS2008 only gives me a limited set of types. Amazingly, enums don't seem to be one of these types that are automatically supported - have I understood this correctly? From reading up on the subject, it seems lik...