enums

Using enum inside types - Compiler warning C4482 C++

I am using fully qualified name of the enum inside a method in one of my class. But I am getting compiler warning which says "warning C4482: nonstandard extension used: enum 'Foo' used in qualified name". In C++, do we need to use enums without the qualified name? But IMO, that looks ugly. Any thoughts? ...

Limit Values for Properties in .NET

I know this may be a noob question, but it's bugging the heck out of me. Let's say I have a user control that I reference in my .aspx page: <uc:somecontrol runat="server" id="uc1" property1="red" /> how do I make it so when in VS05 the intellisense will show options like "red", "green", "blue" for property1? Similar to how when you w...

Enum subset or subgroup in C#

I have an existing enum with numerous items in it. I also have existing code which does certain things with this enum. I would now like a way to view only a subset enum members. What I'm looking for is a way to divide my enum into groups. I need to preserve the (int) value of each member and I need to preserve the ability to view al...

Enumeration and constants

Is there better way than declare enumeration as public enum DepthNumberSize { Bit1 = 1, Bit4 = 4, Bit8 = 8, Bit16 = 16, Bit32 = 32 } and every time when operations with related data chunk performed switch statements are used, like: switch(size) { case DepthNumberSize.Bit1: buffer[i++] = input[j] & 1; ...

Why is compareTo on an Enum final in Java?

An Enum in Java implements the Comparable interface. It would have been nice to override Comparable's compareTo method, but here it's marked as final. The default natural order on Enum's compareTo is the listed order. Does anyone know why a Java Enum has this restriction? ...

object is to class as enum is to ...?

object is to class as enum is to ...? I'm using C# but I'd like the answer for Java as well, if there is one. Thank you, as always. ...

Checking whether all enum values are mapped?

Is there a convenience method available in the java standard libraries to check whether all possible keys in an EnumMap are mapped to a value? I can write my own method like: public static <T extends Enum<T>> boolean areAllValuesMapped(EnumMap<T, ?> map, Class<T> enumClass) { return map.keySet().equals(EnumSet.allOf(enumClass)); } ...

Enum bitfield container class

Im trying to write a small class to better understand bit flags in c++. But something isnt working out. It prints the wrong values. Where is the problem? Have I misunderstood how to add flags? Or check if the bit field has them? Heres the code: #include <iostream> enum flag { A = 1, B = 2, C = 4 }; class Holder { public: Hold...

pythonic replacement for enums

In my python script i am parsing a user created file and typically there will be some errors and there are cases were i warn the user to be more clear. In c i would have an enum like eAssignBad, eAssignMismatch, eAssignmentSignMix (sign mixed with unsigned). Then i would look the value up to print an error or warning msg. I link having t...

C#: Enum.IsDefined on combined flags

I have this enum: [Flags] public enum ExportFormat { None = 0, Csv = 1, Tsv = 2, Excel = 4, All = Excel | Csv | Tsv } I am trying to make a wrapper on this (or any, really) enum which notifies on change. Currently it looks like this: public class NotifyingEnum<T> : INotifyPropertyChanged where T : struct { ...

Choosing the default value of an Enum type without having to change values

In C#, is it possible to decorate an Enum type with an attribute or do something else to specify what the default value should be, without having the change the values? The numbers required might be set in stone for whatever reason, and it'd be handy to still have control over the default. enum Orientation { None = -1, North = 0...

Unexpected result when using Enum.Parse()

class Program { static void Main(string[] args) { String value = "Two"; Type enumType = typeof(Numbers); Numbers number = (Numbers)Enum.Parse(enumType, value); Console.WriteLine(Enum.Parse(enumType, value)); } public enum Numbers : int { One, Two, Three, ...

Handling enums in JSON

When I serialize an object of a class with a enum property to JSON, if the value is null, the resulting json string has a name value pair like this: "controlType":"-2147483648" This causes issues when I deserialize the string to a strongly typed object. What's the best way of handling enums and nulls? ...

Is it OK to use == on enums in Java?

Is it OK to use == on enums in Java, or do I need to use .equals()? In my testing, == always works, but I'm not sure if I'm guaranteed of that. In particular, there is no .clone() method on an enum, so I don't know if it is possible to get an enum for which .equals() would return a different value than ==. For example, is this OK: pu...

What is the best way to populate a WPF combo box with all items from a given enum?

The title pretty much stays it all. Say I have an enum with four values: public enum CompassHeading { North, South, East, West } What XAML would be required to have a ComboBox be populated with these items? <ComboBox ItemsSource="{Binding WhatGoesHere???}" /> Ideally I wouldn't have to set up C# code for this. Tha...

Should enum objects be stateless?

As by design an enum constant in java is a singleton, and for sake of concurrent usage I normally create stateless enum instances and use method parameters to inject the data as needed. Example: Currently I am creating a REST service which has Operations (implemented as an enum using a variant of the strategy pattern). public enum Op...

How to convert a character in to equivalent System.Windows.Input.Key Enum value?

I want to write a function like so, public System.Windows.Input.Key ResolveKey(char charToResolve) { // Code goes here, that resolves the charToResolve // in to the Key enumerated value // (For example with '.' as the character for Key.OemPeriod) } I know I can write a huge ...

Use Spring options tag to display enum's toString value

I'm using Spring for an HTML form. One of the fields is an enum and thus I'd like a HTML drop-down list (<option> tag). My enum's name is different than the toString() value. For example: public enum Size { SMALL("Small"), LARGE("Large"), VERY_LARGE("Very large"); private final String displayName; private Size(String displ...

vb.net, option strict, enums and overriding ToString

I have the following code: Public Enum Country Canada = 1 USA = 2 End Enum When I want to see if the user has selected a value, I do: ddl.SelectedValue = Country.Canada Which works fine. However, if I turn on a warning for implicit conversion, this gives a warning. Changing it to ddl.SelectedValue = Country.Canada.ToString...

Documenting enums using doxygen

The html documentation generated by doxygen for enums lists the enum to the left and the documentation to the right. However I need quite detailed documentation for each value and some of the names are very long thus making the right column with the documentation appear far out to the right and it looks very bad. Is there no possibility ...