Все вопросы: [enums]

559 вопросов

21
голосов
4ответов
25254 просмотров

Iterate through items in an enumeration in Delphi

I want to iterate through the items in an enumeration. I'd like to be able to say something like this: type TWeekdays = (wdMonday, wdTuesday, wdWednesday, wdThursday, wdFriday); ... elementCount := GetElementCount(TypeInfo(TWeekDays)); for i := 0 to elementCount - 1 do begin ShowMessage(G...

3
голосов
3ответов
3503 просмотров

How can I wrap a Java enum and still iterate over it?

How can I have an abstract enum, or some kind of base enum? In my common code I'd like a notion of an enum placeholder, MyItems, without tying myself to a concrete enum. Then in each of my projects I would have a concrete implementation. E.g. Common Code public interface MyItems { // Mar...

1
голосов
3ответов
503 просмотров

Bitwise enum cast return value not expected

I have the following enum: [Flags] public enum PermissionLevel { User = 1, Administrator = 2, ITStaff = 3, Manager = 4, SuperAdministrator = 6, } When I do: PermissionLevel permission = (PermissionLevel) dr.GetInt32(i); I get random permission...

16
голосов
2ответов
43170 просмотров

Hibernate enum mapping

I need to map the enums which didn't implement the interface beforehand to the existing database, which stores enums in the same table as the owner class using the @Enumerated(EnumType.STRING). class A { HasName name; } interface HasName { String getName(); } enum X implements HasName ...

6
голосов
2ответов
1245 просмотров

Mapping custom enum classes with Fluent Nhibernate

Reading some posts from Jimmy Boggard and wondering - how exactly is it possible to map those beasts with fluent nhibernate? How mapping would look like for this? public class EmployeeType : Enumeration{ public static readonly EmployeeType Manager = new EmployeeType(0, "Manager"), ...

9
голосов
4ответов
1510 просмотров

Should I be trying to create a reversible enum in Java or is there a better way?

I seem to have faced this problem many times and I wanted to ask the community whether I am just barking up the wrong tree. Basically my question can be distilled down to this: if I have an enum (in Java) for which the values are important, should I be using an enum at all or is there a better wa...

7
голосов
12ответов
576 просмотров

Possible to have strings for enums?

I want to have an enum as in: enum FilterType { Rigid = "Rigid", SoftGlow = "Soft / Glow", Ghost = "Ghost", } How to achieve this? Is there a better way to do this? It's gonna be used for an instance of an object where it's gonna be serialized/deserialized. It's also gonna populate a ...

102
голосов
6ответов
105292 просмотров

How to get a enum value from string in C#?

I have an enum: public enum baseKey : uint { HKEY_CLASSES_ROOT = 0x80000000, HKEY_CURRENT_USER = 0x80000001, HKEY_LOCAL_MACHINE = 0x80000002, HKEY_USERS = 0x80000003, HKEY_CURRENT_CONFIG = 0x80000005 } How can I, given the string HKEY_LOCAL_MACHINE, get a value 0x80000002...

5
голосов
4ответов
4499 просмотров

How can I associate an Enum with its opposite value, as in cardinal directions (North - South, East - West, etc)?

I'm still working on my Cell class for my maze game I'm attempting to make. After help in a different thread it was suggested that I use an EnumMap for my Walls/Neighbors and this is working great so far. Here is what I have thus far: enum Dir { NORTH, SOUTH, EAST, WEST } class Cell { ...

19
голосов
7ответов
23578 просмотров

Is it bad practice to use an Enum's ordinal value to index an array in Java?

I have two arrays: Walls and Neighbors. public boolean[] walls = new boolean[4]; public Cell[] neighbors = new Cell[4]; and I have an Enum: enum Dir { North, South, East, West } Now, I would like to be able to access walls or neighbors by their direction, so I don't have to ...

4
голосов
6ответов
3045 просмотров

.NET enum size?

How many entries can an enum in .NET have?

3
голосов
4ответов
13533 просмотров

C# - Returning an Enum? from a static extension method

I've added some extension methods for strings to make working with some custom enums easier. public static Enum ToEnum<T>(this string s) { return (Enum)Enum.Parse(typeof(T), s); } public static bool IsEnum<T>(this string s) { return Enum.IsDefined(typeof(T), s); } Note -- ...

12
голосов
4ответов
7993 просмотров

Access Map<enum object> in JSTL</enum>

I have: public enum MyEnum{ One, Two, Three } From controller, I put in the model: HashMap&lt;MyEnum, Long&gt; map = new HashMap&lt;MyEnum, Long&gt;(); map.put(MyEnum.One, 1L); mav.addObject( "map", map); How do I in my JSTL access the object in the map for key enum MyEnum.One, in a nea...

0
голосов
1ответов
967 просмотров

Regular expression substitution for ENUM record

How do I susbtitute in matched groups from 1 regular expression into another regular expression in C#? I need to process an ENUM DNS record where the first half of the record is a regular expression to apply to the lookup value and the second half is a regular expression that uses the matches fr...

6
голосов
2ответов
4546 просмотров

WPF ComboBox/ListBox with MultiSelect based on Enum with Flags

So I may be pushing the boundaries just a bit... Basically I have the following enum, declared in C# code: [Flags] public enum FlaggedEnum : int { Option1 = 1, Option2 = 2, Option3 = 4, Option4 = 8, ... Option16 = 32768, None = 0 } This enum is a member of an objec...

11
голосов
2ответов
16465 просмотров

Using enums in ctypes.Structure

I have a struct I'm accessing via ctypes: struct attrl { char *name; char *resource; char *value; struct attrl *next; enum batch_op op; }; So far I have Python code like: # struct attropl class attropl(Structure): pass attrl._fields_ = [ ("next", POINTER(attro...

3
голосов
3ответов
1627 просмотров

Delphi: How to have non-contiguous subrange enumeration type?

While the following subrange enumeration declaration works: type TReceiptCode = 'A'..'F'; This does not: type TReceiptCode = ' ','A'..'F', 'R'; Nor does type TReceiptCode = ' ','A','B','C','D','E','F','R'; How can i declare a subrange type with non-contiguous values?

3
голосов
3ответов
2321 просмотров

enums and generic methods in java

I still have trouble with some corner cases in the java generics system. I have this method (I'm only interested in the signature) : interface Extractor&lt;RETURN_TYPE&gt; { public &lt;U extends Enum&lt;U&gt;&gt; RETURN_TYPE extractEnum(final Class&lt;U&gt; enumType); } (think about an ...

12
голосов
4ответов
13719 просмотров

How to tell if a PropertyInfo is of a particular enum type?

I have the following code: public class DataReader&lt;T&gt; where T : class { public T getEntityFromReader(IDataReader reader, IDictionary&lt;string, string&gt; FieldMappings) { T entity = Activator.CreateInstance&lt;T&gt;(); Type entityType = entity.GetType(); Pr...

59
голосов
5ответов
44515 просмотров

How to get the numeric value from the Enum?

For example System.Net.HttpStatusCode Enum, I would like to get the HTTP Status Codes instead of the HTTP Status Text. System.Net.HttpStatusCode.Forbidden should return 403 instead of "Forbidden". How can I extract the value?

6
голосов
1ответов
6600 просмотров

How to use the MOQ library to mock an ENum

I am having an issue using the Moq library to mock an Enum within my project. I am trying to test a class and one of the methods accepts an ENum. Is there any way to do this? Here is the Enum I am trying to mock: public enum PermissionType { Create = 0, Read = 1, Update = 2, Del...

11
голосов
3ответов
9526 просмотров

Data bind enum properties to grid and display description

This is a similar question to How to bind a custom Enum description to a DataGrid, but in my case I have multiple properties. public enum ExpectationResult { [Description("-")] NoExpectation, [Description("Passed")] Pass, [Description("FAILED")] Fail } public class Tes...

22
голосов
2ответов
10962 просмотров

How can I extend a lexical cast to support enumerated types?

I have the following function that will convert a string into a numeric data type: template &lt;typename T&gt; bool ConvertString(const std::string&amp; theString, T&amp; theResult) { std::istringstream iss(theString); return !(iss &gt;&gt; theResult).fail(); } This does not work for e...

53
голосов
5ответов
39372 просмотров

How to work with Enums in Entity Framework?

What is the best way to work with Enums in Entity Framework? Remarks: I'm using EF 3 and Firebird.

3
голосов
2ответов
1146 просмотров

Creating a dynamic enum and attempting to reference it fail with BindingFailure

I need to create a dynamic enum and then be able to get the type using Type.GetType(). Is this possible? The below code will create a dynamic enum, and attempt to use it's qualifying name. This is fine if I first store the assembly (using AssemblyBuilderAccess.RunAndSave). However, this is not p...

4
голосов
5ответов
1034 просмотров

Multiple output operators?

is it possible to define multiple output operators for an enum? I want to use this std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, my_enum e); operator to (1) print a human readable text and to (2) convert it to some code for storing in a database. Thanks

0
голосов
3ответов
1932 просмотров

model classes in a database with my own enum types

I have an application that I need to query lifetables (for insurance calculation). I was thinking about using XML to store the data, but thought it was a little big, but maybe a little small for using a full-fledged database. So I chose to use SQLite. In my application, I have enums defining a f...

1
голосов
6ответов
1423 просмотров

#defined bitflags and enums - peaceful coexistence in "c"

I have just discovered the joy of bitflags. I have several questions related to "best-practices" regarding the use of bitflags in C. I learned everything from various examples I found on the web but still have questions. In order to save space, I am using a single 32bit integer field in a struct...

1
голосов
1ответов
2462 просмотров

How can you handle invalid enum types using JAXB?

We are using JAXB to handle our wsdl validation. In the wsdl we have an enumeration like so: &lt;xs:simpleType name="myEnum"&gt; &lt;xs:annotation&gt; &lt;xs:documentation&gt;The enums which matter.&lt;/xs:documentation&gt; &lt;/xs:annotation&gt; &lt;xs:restriction base="xs:s...

25
голосов
12ответов
73404 просмотров

Check valid enum values before using enum

I'm trying to lookup against an Enum set, knowing that there will often be a non-match which throws an exception: I would like to check the value exists before performing the lookup to avoid the exceptions. My enum looks something like this: public enum Fruit { APPLE("apple"), ORANGE("or...