As we know, all enums are compiled as constants, which means you can get unexpected results if you use an enum from a different assembly.
Settings sequential enum numbers explicitly is no help, because if you want to leave room for new values, you have to do basic-linenumber-style spacing, which is naff.
So I wondered about using the h...
Hi I want to write a FindByExample(object o) method. So I tried this:
public IList<T> FindByExample(T o)
{
return Session.CreateCriteria(typeof(T)).Add(Example.Create(o)).List<T>();
}
(It's in a generic class)
It should work fine, but if T has a property of an enum type, it throws this exception:
"Type mismatch in NHibernate.Cri...
I've just got back to MIDP development after some 4 years of .NET 2 and Java 5 and 6. During that time I got to like using enums quite a lot.
Enum is a language feature that allows a developer to have more confidence in some parts of his code, specially for being able to avoid or detect errors earlier (during compilation). Some other ad...
Hello. I was just wondering why people use enums in C++ as constants while they
can use const.
Thanks
...
I have a table called UserPermissions with a FK to the users table by userId and then a string column for the string value of an enum.
The error I am seeing is NHibernate.MappingException: An association from the table UserPermissions refers to an unmapped class: GotRoleplay.Core.Domain.Model.Permission
My Permission Enum:
public ...
I'm porting some old code that uses the int enum pattern to Enum and EnumSet. It is very easy but I don't know how translate the following code to EnumSet: :
int mask = (kind == 'C' ? CLASS_MODIFIERS
: kind == 'F' ? FIELD_MODIFIERS
: kind == 'M' ? METHOD_MODIFIERS
: (CLASS_MODIFIERS | FIELD_MODIFIERS ...
So here's my problem:
struct A
{
enum A_enum
{
E0,
E1,
E2
};
};
struct B
{
typedef A::A_enum B_enum;
bool test(B_enum val)
{
return (val == E1); // error: "E1" undeclared identifier
}
};
I specifically do not want to say A::E1. If I try B_enum::E1 I receive a warning that it...
What results when you pass an empty string to a Java enum .valueOf call?
For example:
public enum Status
{
STARTED,
PROGRESS,
MESSAGE,
DONE;
}
and then
String empty = "";
switch(Status.valueOf(empty))
{
case STARTED:
case PROGRESS:
case MESSAGE:
case DONE:
{
System.out.println("is valid status");
...
Hi, a lot of people have answered the question of how to bind an enum to a combo box in WinForms. Its like this:
comboBox1.DataSource = Enum.GetValues(typeof(MyEnum));
But that is pretty useless without being able to set the actual value to display.
I have tried:
comboBox1.SelectedItem = MyEnum.Something; // Does not work. SelectedI...
I'd like to create a generic method for converting any System.Enum derived type to its corresponding integer value, without casting and preferably without parsing a string.
Eg, what I want is something like this:
// Trivial example, not actually what I'm doing.
class Converter
{
int ToInteger(System.Enum anEnum)
{
(int)...
I'm just learning ruby on rails and I have a table of user roles (Owner, Admin, and User). There are going to be places in the code where I need to check the user's role and show different options. Does anyone know how to do this without resorting to magic numbers or other ugly methods?
In ASP.Net web apps I've worked on I've seen thi...
I have some code that sets up a dictionary with some defualt values for an enum:
foreach (string status in Enum.GetNames(typeof(TargetStatusType)))
{
dict.Add((TargetStatusType)Enum.Parse(typeof(TargetStatusType), status), 0);
}
Is there an easier way to do this, as it seems a bit messy.
I was hoping I could just do
foreach(Targ...
I'm trying to use Prism and the MVVM pattern to develop an application. In my UI, I have a previous and next button defined. For use in a calling web services, I've defined an enum that will tell me the direction I need to traverse. So, in this instance, the buttons map directly to an enum value. The enum definition is very simple a...
This is my starting point link text to expose an enum which the Client can consume; it is not part of method signature. My code compiles but I am unable to view it in wsdl and unable to use it in my C# windows form application test project. Is the test code in the link missing something?
...
This stackoverflow question has an interesting discussion on how to avoid giving enums and properties the same names so that you don't have code like this:
public SaveStatus SaveStatus { get; set; }
It seems the accepted answer suggested to use "State" for the enum and "Status" for the property:
public SaveStatus SaveState { get; set...
Hello,
I want to create an enumcombobox where the popup will show the enumvalues of the controls' binding object. Somehow I cannot get the binding object property at runtime. Databindings wil get me to the binding object. But the property and its type is invisable for me, or I just didn't find it yet... Can anyone help me with this?
...
So, I've got this definition:
typedef enum {
red = 1,
blue = 2,
white = 3
} car_colors;
Then, I've got a variable of type car_colors:
car_colors myCar;
The question is, I receive the color of the car in a NSString. It must be a NSString, I can't change that. How can I convert from NSString to car_colors type?
NSString ...
Hi, I have got a task table in my database with a priority field containing an integer value from 1 to 4 as a test. I am using a LINQ to SQL dbml file so I have a task class and I want to be able to display the text value of the priority to the user in my view, as a value in a select list.
I have added the below code to my task class:
...
I have a list of rather meaningless codes that I'm processing with a VB.NET Windows application. For the business logic I'm writing to process those codes, I'd like to use meaningful constants (like ServiceNotCovered or MemberNotEligible) instead of the original codes (like "SNCV" and "MNEL").
As far as I can tell, Enums can only map to...
I'd like to use the same enum across three tiers of my application (presentation -> bal -> dal). I defined the enum in the data layer and I want to use the same enum in the presentation layer (the presentation layer does not have a reference to the data layer). Using someone else's answer to what I think is a similar question, I've bui...