enums

Can an enum be defined in the same file as a class header that uses it in Objective-C?

If not, and it needs to be included in a separate file (e.g. MyEnums.h) do I need to #import MyEnums.h every time a .m or .h file wants to refer to the type or one of the values? Here's sample code of MyClass.h: #import <Foundation/Foundation.h> // #1 placeholder @interface MyClass : NSObject { } // #2 placeholder - (void)sampleM...

C# Enumerations and Duplicate Values - dangers?

I was wondering about C# Enumerations and what happens with duplicate values. I created the following small program to test things out: namespace ConsoleTest { enum TestEnum { FirstElement = -1, SecondElement, ThirdElement, Duplicate = FirstElement } /// <summary> /// Summary descri...

Java Enums: de-serializing an arbitrary enum from a file

A co-worker ran into an interesting issue today, and while I think the actual, big-picture answer is "the fact that we're having this problem means we're doing something wrong", I figured I'd ask this anyway. Given the following: public class CrazyEnumTest { public class EnumeratedThing<T extends Enum<T>> { public T myValue; ...

WPF user control with a property of type Enum

I have a usercontrol called "InputSensitiveTextBox" that inherits from Textbox. It has a property I define called "CurrentInputType", which is of type "MyControlsNamespace.SupportedInputTypes" (with values Keyboard, Mouse, Touchpad, VirtualKey). I need to have this property be set in Xaml just like I might set "HorizontalAlignment" or ...

wpf binding a combobox to an enum nested in a class

I have been going crazy with binding a combobox to an enum typed property of a class, where the enum itself is declared in that same class. I am trying to follow the answer provided here (wpf combobox binding to enum what i did wrong?) Specifically I am using the suggested MarkupExtension code and the matching xaml code. My working c...

Is there a point at which an Enum can get too bloated?

I've defined an Enum as part of the model objects for an ASP.NET MVC application. The Enum is called 'ContentTypes' and looks something like this: public enum ContentTypes { [Description("News story")] NewsStory = 1, [Description("Article")] Article = 2 } Now I'm planning to add another set of attributes to the enum ...

C18 compiler typedef enum data size

I'm trying to port code over to compile using Microchip's C18 compiler for a PIC microcontroller. The code includes enums with large values assigned (>8-bit). They are not working properly, indicating that, for example, 0x02 is the same as 0x2002. How can I force the enumerated values to be referenced as 16-bit values? ...

Hibernate 'tableless' enum mapping?

I am dealing with the following scenario: We use table-per-subclass inheritance, meaning the concrete tables' primary keys are foreign key references on the abstract table. Superclass is Product, subclasses are Book, DVD, AudioCD, ... Now in the Java superclass, say Product.java, we have an enum of the types of products: book, dvd, mu...

How can I make something like a dynamic enumeration in C#?

In an application I'm building I had an enumeration of account statuses: public enum AccountStatus { Active = 1, Trial = 2, Canceled = 3 } However, I needed more information from an AccountStatus so I made a class which has a few extra useful properties: public class AccountStatus { public int Id {get; se...

Converting between C enum and XML

What's the cleanest way to store an enum in XML and read it back out again? Say I've got: enum ETObjectType {ETNormalObjectType, ETRareObjectType, ETEssentialObjectType}; ...and I want to take a variable, enum ETObjectType objectType = ETNormalObjectType;, and convert it to XML that looks like this: <objectType>ETNormalObjectType</obj...

Associating Strings with enums in C#

I work on C# window ...vs05 ......i want to put space on enum string ....i do it below code have this.....My problem is after select a value from the combo how can i get the index number of this value .....and if i gone to edit mode then i need to show the value what is user already selected .....how to get enum selected value on basis o...

Confusion with C# Enum and Explicit conversion

I have the following enum --> public enum SyncStatus { Unavailable = 0, Checking = 5, StartedAspNetDb = 10, FinishedAspNetDb = 20, StartedMatrixDb = 30, FinishedMatrixDb = 40, StartedConnectDb = 50, FinishedConnectDb = 60, StartedCmoDb = 70, Finished...

Polymorphically convert Java enum values into a list of strings

I have a handful of helper methods that convert enum values into a list of strings suitable for display by an HTML <select> element. I was wondering if it's possible to refactor these into a single polymorphic method. This is an example of one of my existing methods: /** * Gets the list of available colours. * * @return the list o...

Is there a way to use macros to add additional values to an enum from elsewhere at compile time?

We use one big enum for message passing and there are optional parts of our code base that use specific messages that really only need to be added to the enum if those parts are to be compiled in. Is there a way to define a macro that could do this or something similar? I would like to be able to just add REGISTER_MSG(MESSAGE_NAME); to ...

where is Enum.values() defined?

Hi, Every Java enumeration has a static values() method can be used like this for (MyEnum enum : MyEnum.values()) { // Do something with enum } However, I cannot figure out where this method is defined. There's no mention of it in the Javadoc and it doesn't appear anywhere in the source file. ...

How to store linear range of values? Which Data structure to choose?

I need a simple structure to store polygon names based on sides ... so for e.g. 1 side is "monogon", 2 sides is "digon", 3 sides is "triangle" and so on (say for upto 12 sides) What is the simplest way to store these and reuse them in the code dynamically? for e.g. if my polygonShape class has 3 as the number of sides, it should return "...

How can I use the string value of a C# enum value in a case statement?

I have defined a C# enum as public enum ORDER { ... unknown, partial01, partial12, partial23, } and can use its value as a string as in: string ss = ORDER.partial01.ToString(); However when I try to use it in a case statement it fails to compile: string val...

Is it possible to expose a C# Enum to COM Interop callers, and if so, how?

I have a managed assembly that gets called via COM Interop. Like a VBScript client, a Perl client, and so on. The classes are decorated with [ClassInterface(ClassInterfaceType.AutoDual)] [GuidAttribute("ebc25cf6-9120-4283-b972-0e5520d0000E")] [ComVisible(true)] Then of course I do the regasm thing, and all the methods work just fi...

pass reflected enum to method.invoke java

If you have an enum that you are accessing via reflection how would you pass it's value into method.invoke call. Would it be something like (shown as a static method for simplicity) Class enumClazz = Class.forName("mypkg.MyEnum",true,MyClassLoader); Class myReflectedClazz = Class.forName("mypkg.MyClass",true,MyClassLoader); ...

Enumerations in the database and O/RM

Suppose I want entries in the table Regions to have a type, e.g. a city, a country etc. What's the accepted way of storing this type, assuming I'll be using O/RM (NHibernate in my case) ? I see two options: Have an enum in the C# bussines layer with the types and store the type as a tinyint in the table. Have a lookup table RegionType...