enums

Mapping enum to a table with hibernate annotation

I have a table DEAL and a table DEAL_TYPE. I would like to map this code: public class Deal { DealType type; } public enum DealType { BASE("Base"), EXTRA("Extra"); } The problem is that the data already exist in the database. And I'm having a hard time mapping the classes to the database. The database looks something like that...

All Enum items to string (C#)

How to convert all elements from enum to string? Assume I have: public enum LogicOperands { None, Or, And, Custom } And what I want to archive is something like: string LogicOperandsStr = LogicOperands.ToString(); // expected result: "None,Or,And,Custom" ...

Flex & WCF - Enum problem

I have a WCF service operation that accepts a data contract parameter of custom type MyQuery -- function Search(q as MyQuery). The MyQuery object contains 2 properties: MyQuery.SearchPhrase (string) MyQuery.SearchType (custom enum SearchTypeEnum) I also have a Flex client application that consumes this service. But when Flex invokes ...

Flags enum in .NET

I am trying to use a set of conditional statements that will set up an enumeration attributed with [Flags]. However, the compiler complains that 'm' is unassigned. How can I rewrite the following to achieve my intended functionality? Media m; if (filterOptions.ShowAudioFiles) m = m | Media.Audio; if (filterOptions.ShowDocumentFiles)...

Returning an enum from a function in c?

If I have something like the following in a header file: enum Foo { BAR, BAZ }; how do I declare a function that returns an enum of type foo? Can I just do something like the following: Foo testFunc() { return Foo.BAR; } Or do I need to use typedefs or pointers or something? ...

Creating / Modifying Enums at Runtime

I'm creating a program where the user has the option of creating their own custom properties that will ultimately be displayed in a PropertyGrid. Right now I don't want to mess with custom editors, so I'm only allowing primitive type properties (string, int, double, datetime, bool etc.) that the PropertyGrid already has built in editors ...

Best practices for using and persisting enums

I've seen several questions/discussions here about the best way to handle and persist enum-like values (e.g. http://stackoverflow.com/questions/492096/persisting-data-suited-for-enums , http://stackoverflow.com/questions/256978/how-to-persist-an-enum-using-nhibernate ), and I'd like to ask what the general consenus is. I've tried to sum...

Get Integral Value of Boxed Enum

Hey All, I have decided it is impossible to do the following (equivalent) enum operations via reflection - as the Enum class has no operators, and nor does the emitted code expose any operators: object boxedEnum = MyEnum.Flag1 | MyEnum.Flag2; boxedEnum &= ~MyEnum.Flag2; // Remove the flag. So I am currently doing the following (equiv...

Finding unused enum members

What is the quickest way to determine which members of an enum are not being used? ...

Enum "Inheritance"

I have an enum in a low level namespace. I'd like to provide a class or enum in a mid level namespace that "inherits" the low level enum. namespace low { public enum base { x, y, z } } namespace mid { public enum consume : low.base { } } I'm hoping that this is possible, or perhaps some kind of class that can ...

Generic Array of Enum Values?

Hey all, I'm currently writing a helper function in VB.NET to convert an array of enum values to a CSV, but I'm encounting a few difficulties.... I'm not sure what type of arguement my function should take if I want to make it generic enough to handle any enum I pass into it. This is what I've got so far: Public Shared Function EnumA...

How can I use a User Defined Type (UDT) in a COM server?

I have a COM server with a method currently returning an integer: [ object, uuid("..."), dual, helpstring("IMyCOMServer Interface"), pointer_default(unique) ] __interface IMyCOMServer : IDispatch { [id(1), helpstring("method MyQuery")] HRESULT MyQuery([in] BSTR instr, [out,retval] int* outint); }; This comp...

Should I store Enum ID/values in the db or a C# enumeration?

Say my database tables have columns like UserType, SalesType, etc. Should I have database tables with UserTypeID, userTypeName or should I just create a C# enumeration? ...

2 C enum questions

Part 1 In C, is there any difference between declaring an enum like this: typedef enum{VAL1, VAL2,} firstEnum; and like this: enum secondEnum{Val1, Val2,}; Apart from the fact that when using secondEnum, you have to write: enum secondEnum...; Part 2 Also, am I right in thinking that the following is equivalent: enum{Val1, Val...

Is the last comma in C enum required?

Is the last comma required in a C enum declaration? i.e. is the comma after VAL3 required? enum{Val1, Val2, Val3,} someEnum; Are there any side-effects of leaving it in/out Thanks ...

How do I override ToString in C# enums?

In the post Enum ToString, a method is described to use the custom attribute DescriptionAttribute like this: Enum HowNice { [Description("Really Nice")] ReallyNice, [Description("Kinda Nice")] SortOfNice, [Description("Not Nice At All")] NotNice } And then, you call a function GetDescription, using syntax like: GetDescrip...

Simple iteration through an Integer-type enum?

Hi, I have the following Enum: Public Enum myEnum As Integer first = &H1 second = &H2 third = &H4 fourth = &H8 fifth = &H10 sixth = &H20 End Enum It is neccessary, unfortunately, that the enum elements have those values, or at least have values that can be binary compared. I have a class which can be set d...

Hibernate Complex type save

i need to persist an object whose one of the properties is an enum. This whole structure have to be saved in a single table. The enum defines the possible genders public enum Gender { MALE,FEMALE } The main class is public Person { String name; Gender gender; } If this Person class has to be persisted in a single table, how should...

ComboBox bound to an enum type's values while also having a "blank" entry?

If I bind a WinForms ComboBox to an enum type's values, i.e. combo1.DropDownStyle = ComboBoxStyle.DropDownList; combo1.DataSource = Enum.GetValues(typeof(myEnumType)); Who knows how I could achieve the same result, while, in addition to entries matching each enum value, I can also have a blank entry representing no selection? I canno...

SubSonic 'Generate Enums from Lookup Tables'

I was asked by a fellow developer if I could code in some enums into SubSonic as he was needing them and he pointed out a post on the old SubSonic forums. If anyone is interested in this functionality then an issue has been opened at http://code.google.com/p/subsonicproject/issues/detail?id=81 if you'd like to place some comments and fe...