enums

Binding ComboBoxes to enums... in Silverlight!

So, the web, and StackOverflow, have plenty of nice answers for how to bind a combobox to an enum property in WPF. But Silverlight is missing all of the features that make this possible :(. For example: You can't use a generic EnumDisplayer-style IValueConverter that accepts a type parameter, since Silverlight doesn't support x:Type. Y...

Is there any well-known paradigm for iterating through enum?

Greetings, everyone! I have a c++ code, where the following enum is declared: enum Some { Some_Alpha = 0, Some_Beta, Some_Gamma, Some_Total }; int array[Some_Total]; The values of Alpha, Beta and Gamma are sequential, and I gladly use the following cycle to iterate through them: for ( int someNo = (int)Some_Alpha; someN...

C++ enum from char

Ok, I'm new at C++. I got Bjarne's book, and I'm trying to follow the calculator code. However, the compiler is spitting out an error about this section: token_value get_token() { char ch; do { // skip whitespace except '\n' if(!std::cin.get(ch)) return curr_tok = END; } while (ch!='\n' && isspace(ch)); ...

TryParsing Enums

I am parsing some enum values from a text file. In order to simplify things I am using functions like the following: (The sample code here uses C++/CLI but answers in C# are also welcome.) bool TryParseFontStyle(String ^string, FontStyle% style){ try { FontStyle ^refStyle = dynamic_cast<FontStyle^>( Enum::Parse(FontStyle...

sorting enum for UI purpose

say we have a ui and in this ui we have a dropdown. this dropdown is filled with the translated values of an enum. now, we have the possibility to sort by the int-value of the enum, by the name of the enum, and by the translated name of the enum. but what if we want a different sorting than the 3 mentioned above. how to handle such a r...

Can you refer to a named enum as if it were anonymous in D?

I'm doing a D bridge to a C library, and this has come up with the C code using typedef'd enums that it refers to like a constant, but can name it for function arguments and the like. Example: enum someLongNameThatTheCLibraryUses { A, B, } Currently, I must refer to it like so: someLongNameThatTheCLibraryUses.A; But I wou...

template function specialization problem

Hello! I am using templates to implement a range checked conversion from int to enum. It looks like this: template<typename E> E enum_cast(const int &source); The template function placed more or less in the root-directoy of the project. When defining a new enum that is foreseen to be assigned values from a config file like this: en...

Is there a (well hidden) generic enum anywhere in the BCL for Enabled/Disabled?

So, I just hate using true/false as method arguments for "enabled"/"disabled". To freely quote Jeff: "I dislike it on a fundamental level". I repeatedly find myself defining my own enums on every new project in different namespaces all over the place, like these: public enum Clickability { Disabled, Enabled } public enum Edita...

Enum with Generics

UPDATE: Disregard this question. I had an inadvertent import in my abstract class that was the same name as COLUMNS... Someone please delete. I'm encountering a weird issue with Generics and Enum. Here are the relevant code: public abstract class AbstractModel<E extends Enum<? extends E>> { protected abstract Object getValue(in...

Scala doesn't have enums - what to use instead of an enum

Scala doesn't have type-safe enums like Java has. If I have a set of related constants then what is the best way in Scala to represent those constants? ...

How do I get the value in an enum for a particular name?

Basically I'm writing my own version of a 'RoleProvider' and 'AuthorizeAttribute'. I've got an Enum (as a bit field) with a list of all possible roles: namespace myProject.Global { [Flags] enum Roles { Viewer = 1, User = 2, Admin = 4, Superadmin = 8 } } My AuthorizeAttribute works simil...

Using a var based on an enum in a Where clause in Entity Framework throws an exception.

I have the following code which throws an exception (detail in code comments below). I am merely trying to use an instance of an enum as part of the Where clause. I understand the message, but I don't understand why EF cannot parse an Int32 enum. It works if I copy the enum to an Int32 and then filter on that, but it seems very messy. ...

FilterOperators or FilterOperatorType - The correct naming format for an enum in C#

Which is the appropriate (more readable) way of naming enumerator? will you consider: enum FilterOperators { IsEqual, Contains, StartsWith } class QueryFilter { FilterOperators Operator{get;set;} } var filter = new QueryFilter(); filter.Operator = FilterOperators.IsEqual; Or is this preferable enum FilterOperatorT...

How to have userfriendly names for enumerations?

Hi, I have an enumeration like Enum Complexity { NotSoComplex, LittleComplex, Complex, VeryComplex } And I want to use it in a dropdown list, but don't want to see such Camel names in list (looks really odd for users). Instead I would like to have in normal wording, like Not so complex Little complex (etc) Also, my applicat...

Enum type constraints in C#

What is the reason behind C# not allowing type constraints on Enum's? I'm sure there is a method behind the madness, but I'd like to understand why it's not possible. Below is what I would like to be able to do (in theory). public static T GetEnum<T>(this string description) where T : Enum { ... } ...

Efficient way to find the flags enum length?

Consider this: [Flags] enum Colors { Red=1, Green=2, Blue=4 } Colors myColor=Colors.Red|Colors.Blue; Currently, I'm doing it as follows: int length=myColors.ToString().Split(new char[]{','}).Length; But I hope there is a more efficient way of finding the length, maybe based on bitset operations. Please, if possible, p...

flag enum confusion C#

According to my code a=1, b=2, c=3 etc. I thought the flag would make a=1, b=2, c=4, etc [Flags] public enum someEnum { none, a, b, c, d, e, f, } How do i get what i intended(c=4, e=8)? and what does the [Flags] mean above? ...

c++ problem with enum and struct

why doesn't this compile: enum E { a, b} typedef struct { int i; E e; } S; int main(){return 0;} I get different errors on different system. ...

Enum Ploblem alway value how?

public enum FrameStatus { NotReport = 0, NormalStatus = 1, NotNormalstatus = 2 } but alway FrameStatus.NormalStatus how? public FrameStatus FrameReportStatus(int Framid, string Timebet) { foreach (FrameCam fc in al) { if (fc.Timebet == Timebet && fc.IdFrame == Framid) { if ((int)fc.status...

C#: How to check if any flags of a flag combination are set

Let's say I have this enum: [Flags] enum Letters { A = 1, B = 2, C = 4, AB = A | B, All = A | B | C, } To check if for example AB is set I can do this: if((letter & Letters.AB) == Letters.AB) Is there a simpler way to check if any of the flags of a combined flag constant are set than the following? if((let...