enums

WCF deserialization of Dictionary where Enum type is key

Hello there. I would like to aks you for your help. I have here problem with WCF deserialization of Dictionary where Enum type is used as a key. I have two data objects: [DataContract] public enum MyEnum : int { [EnumMember] Value1 = 0, [EnumMember] Value2 = 1 } and [DataContract] [KnownType(typeof(MyEnum))] public cl...

JPA/Hibernate, @Embedded and Enum

Hi, I'm trying to persist an Enum as an Embedded value (ideally using it's String representation, but even ordinal would be ok right now) The Enum: @Embeddable public enum DayOfTheWeek { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY; public int toCalendar() throws EnumConstantNotPresentException{ switch (this) { ...

C# Enum.Parse Generics

I have regularly wondered why C# has not yet implemeted a Generic Enum.Parse Lets say I have enum MyEnum { Value1, Value2 } And from an XML file/DB entry I wish to to create an Enum. MyEnum val = (MyEnum)Enum.Parse(typeof(MyEnum), "value1", true); Could it not have been implemented as something like MyEnum cal = Enum.Parse<...

use class and enum with same name?

I've a class and an enum value which have the same name. Inside the class I want to use the enum which gives an error. Is there any way to use the enum without renaming or moving to a different namespace? Example: namespace foo { enum bar { BAD }; class BAD { void worse () { bar b = BAD; // erro...

abstract java enum

I write a library that should rely on enums but the actual enum should be defined be the user of my library. In the following example the authorize method requires parameters of the enum type Permission. acl.authorize(userX, Permission.READ, Permission.WRITE) My library should be able to handle arbitrary permissions defined by the ...

Nested Enum and Property Naming Conflicts

There are some related questions here and here, but they didn't really give me satisfactory answers. The problem is that enums nested in a class in C# cannot have the same name as a property of the class. My example: public class Card { public enum Suit { Clubs, Diamonds, Spades, Hearts } ...

How to avoid using Enums?

Until asking a question on here I never considered (enums) to be a "bad thing." For those out there that consider them not to be best practice, what are some approachs/patterns for avoiding their use in code? Edit: public Enum SomeStatus Approved = 1 Denied = 2 Pending =3 end Enum ...

Getting all the enum values from enum value

Hi All I came across thas problem that I without knowing the actual enum type i need to iterate its possible values. if (value instanceOf Enum){ Enum enumValue = (Enum)value; } Any ideas how to extract from enumValue its possible values ? Thanks ...

DDD: Can I have my persistence layer object implement an interface that uses enum, with implicit conversion to int?

I have a domain interface public interface ITicket { ... TicketWorkflowStatus StatusId{get;set;} // Enum } but the linq-to-sql persistance layer on the database wants to use int, can I change it in the dbml so that the local type is TicketWorkflowStatus? What are my options? ...

NHibernate - Mapping one property to two or more fields?

I have a database table that includes a two bit fields: IsEvenSide and IsOddSide. I want this to map to the following enum: [Flags] enum SideOfStreet { None, Even, Odd } I have done IUserType's in the past, but I don't know how to map to multiple database fields. How can this be done? P.S.: I'm using Fluent NHibernate, but I'm okay ...

AutoMapper: Map Source property of concrete subclass to an EnumValue in Destination class

I would like to define a mapping (or even a TypeConverter/Resolver) for the following classes: Destination: public class Destination { public DestinationEnum EnumProperty { get; set; } public Destination() { EnumProperty = DestinationEnum.undefined; } } public enum Destination...

Should enums in C# have their own file?

I have a class which uses an enumeration, the enum is currently in it's own file which seems wasteful. What is the general opinion on enums being placed within the namespace of a file that they are consumed in? Or should the enum really live in it's own cs file? Edit I should mention that while the class in question uses these enume...

Clean way to pass an enum to a function with the option of passing null in C#

I have an object that represents a physical structure (like a utility pole), and it touches a bunch of other objects (the wires on the pole). The other objects have a bunch of characteristics (status, size, voltage, phase, etc.) expressed as enums. I want to write a generic function that counts how many of the wires match any or all of t...

Java ENUM problem

I have two Enums as follows: enum Connector { AND, OR, XOR; } enum Component { ACTIVITY } Now, I have a variable named follower in a class Event. This variable (follower) can have (and should have) value from either of the above two Enums. So, What datatype should I give to the follower variable? ...

How to prevent empty values of enum column in MySQL

mysql> CREATE TABLE foo ( f ENUM('a', '123') ); mysql> insert into foo(f) value(3); Query OK, 1 row affected, 1 warning (0.00 sec) mysql> select * from foo; +------+ | f | +------+ | | +------+ How to make it produce a failure when inserting a value out of range? ...

How to check if a parameter value is in a list of constants

I have a list of constants and want to check if a value passed to a method equals one of the constants. I know Enums which would be fine, but I need an int value here for performance reasons. Enum values can have a value, but I'm afraid the getting the int value is slower than using an int directly. public static final int a = Intege...

In Java are the object instances for field constants that represent an enum type instantiated only when first accessed?

How are enums handled when it comes to the heap, memory, and when an enum type instance is created? If I've got an enum with fifty field constants, then do I have fifty objects on the heap representing that enum type (when accessed), and are there performance concerns? ...

Sort NameValueCollection against Enum

I have to sort a namevaluecollection(Items usually 5 to 15) Against an enum(having items more than 60). Right now I am using this extension function, Anyone have better idea to write this code.... public static NameValueCollection Sort(this NameValueCollection queryString, Type orderByEnumType, bool excludeZeroValues) { ...

Exposing Unused Enum from a WCF service

I want to expose an enum to my client application without referencing it in my WCF Service. However the enum is not visible in the client application. Below is my code: [DataContract] public enum Columns { [EnumMember] Column1= 0, [EnumMember] Column2= 1 } [ServiceKnownType(typeof(Columns))] public interface IService { ...

In Java, how do I get the value of an enum inside the enum itself?

I want to override toString() for my enum, Color. However, I can't figure out how to get the value of an instance of Color inside the Color enum. Is there a way to do this in Java? Example: public enum Color { RED, GREEN, BLUE, ... public String toString() { // return "R" for RED, "G", for GREEN, etc. }...