enums

enums for constants in java - is this good style?

In java <1.5, constants would be implemented like this public class MyClass { public static int VERTICAL = 0; public static int HORIZONTAL = 1; private int orientation; public MyClass(int orientation) { this.orientation = orientation; } ... and you would use it like this: MyClass myClass = new MyClass(My...

enum-int casting: operator or function

In the external code that I am using there is enum: enum En {VALUE_A, VALUE_B, VALUE_C}; In another external code that I am using there are 3 #define directives: #define ValA 5 #define ValB 6 #define ValC 7 Many times I have int X which is equal to ValA or ValB or ValC, and I have to cast it to the corresponding value of En (ValA...

How can this Linq2Sql create an enum in the select clause?

Hi folks, i've got the following linq2sql query, and i'm setting the result to a POCO. One of my POCO properties is an enumeration. public IQueryable<Models.Achievement> GetAchievements() { return from a in _sqlDatabase.Achievements select new Models.Achievement { // Note: ToEnum is an extension ...

What datatype do you use for enumerations in SQL Server

When we serialize an enum from C# to SQL Server we use a NCHAR(3) datatype with mnemonic values for each value of the enum. That way we can easily read a SELECT qry. How do you save enum to your database? What datatype do you use? ...

Are varargs allowed in a java enum constructor?

enum MyEnum { A( 1, 2, 3, 4), B(1, 2), C(4, 5, 8, 8, 9); private MyEnum( int firstInt, int... otherInts ) { // do something with arguments, perhaps initialize a List } } Are there any problems with this? Any reasons not to do it? ...

Convert C++ Header Files To Python

I have a C++ header that contains #define statements, Enums and Structures. I have tried using the h2py.py script that is included with Python to no avail (except giving me the #defines converted). Any help would be greatly appreciated. ...

Linq To SQL OrderBy, issue when using enums

Hey! I am having some issues with using the OrderBy extension method on a LINQ query when it is operating on an enum type. I have created a regular DataContext using visual studio by simply dragging and dropping everything onto the designer. I have then created seperate entity models, which are simply POCO's, and I have used a repositor...

Get the Integer value of an enumeration which is a generic

Here is the basic situation. Public Class MyEnumClass(of T) Public MyValue as T End Class This is vast oversimplification of the actual class, but basically I know that T is an enumeration (if it is not then there will be many other problems, and is a logical error made by the programmer) Basically I want to get the underlying int...

Should we always favor polymorphism over enums?

After watching: The Clean Code Talks -- Inheritance, Polymorphism, & Testing I checked my code and noticed a few switch statements can be refactored into polymorphism, but I also noticed I only used switch statements with enums. Does this mean enums are "evil" in OO-design and should be eliminated with polymorphism? ...

What is the tilde (~) in a C# enumeration?

I'm always surprised that even after using C# for all this time now, I still manage to find things I didn't know about... I've tried searching the internet for this, but using the "~" in a search isn't working for me so well and I didn't find anything on MSDN either (not to say it isn't there) I saw this snippet of code recently, what ...

Trying to design an object model - using enums

I am trying to design an object model (for C#), and can't work out the best way to store the data. I'll try to use a simple example to illustrate this! I have an object "pet", which could be one of, "cat", "dog" etc. So I have created an "pet" class with a "petType" enum to store this. Now this is where it gets tricky. If an "pet" is a...

WPF: How to bind RadioButtons to an enum?

I've got an enum like this: public enum MyLovelyEnum { FirstSelection, TheOtherSelection, YetAnotherOne }; I got a property in my DataContext: public MyLovelyEnum VeryLovelyEnum { get; set; } And I got three RadioButtons in my WPF client. <RadioButton Margin="3">First Selection</RadioButton> <RadioButton Margin="3">The Other...

WPF: Ideas to set an flag enum value for a single object using Binding Mechanism

I have a Enum for example... public enum TypeIdentifier { NotSet = 0, Type1= 1, Type2= 2, Type3= 3, Type4= 4, Type5= 5 } public class CommonObject { TypeIdentifier myTypeIdentifier {get; set;} } I have a WPF UserControl that has a generalized object binding.I have a c...

Linq returns list or single object

I have a Linq to Entities query like this one: var results = from r in entities.MachineRevision where r.Machine.IdMachine == pIdMachine && r.Category == (int)pCategory select r; Usually, I use the code below to check if some results are returned: if (results.Count() > 0) { return new o...

Using an enum as an array index

I have this enum: enum ButtonState { BUTTON_NORMAL = 0, BUTTON_PRESSED = 1, BUTTON_CLICKED = 2 }; const u8 NUM_BUTTON_STATES = 3; In my Button class I have member variables ButtonState state; and ButtonColors colors[NUM_BUTTON_STATES];. When drawing the button, I use colors[state] to get the colours for whatever state the...

C# - are all Enum constants?

Are all Enum enumerations constants? Do they get converted to their value at compile-time, or at run-time? ...

Performance comparisons betweeen enum evaluations and ints

Would there be difference in speed between if (myInt == CONST_STATE1) and if (myEnum == myENUM.State1) in c#? ...

Can Java Enumerations be merged (like Bitwise in C#)?

Is there a way in Java to declare an enumeration whose values can be used together? For example: enum FileAccess { Read, Write, ReadWrite } Is it possible to define ReadWrite as Read | Write (or anything that would yield the same result)? ...

Uml class diagram enum

Hi I am modeling a class diagram. An attribute of a class is an enumeration. How do i model this? Normally you do something like this: - name : string But how to do this with an enum? Thnx in advance :) ...

WPF: how to display enum property values in vs2008 xaml editor intellisense?

i created a wpf custom control with a dependency property of an enum type. i want the user of that control when editing the xaml in vs to see the optional values of the enum in the intellisense window. does anyone know how it can be done? ...