enumeration

Enumerate over an enum in C++

In C++, Is it possible to enumerate over an enum (either runtime or compile time (preferred)) and call functions/generate code for each iteration? Sample use case: enum abc { start a, b, c, end } for each (__enum__member__ in abc) { function_call(__enum__member__); } Plausible duplicates: C...

Enumerate an IDictionary.Keys collection which is an ICollection<T>

I hope i don't get slammed for asking something so basic. I could Google for the answer, but I want to hear something that's not from a textbook. I'm writing a unit test to verify that my IDictionary Keys are sequential. Since the Keys property is an ICollection<T>, I want to enumerate over the collection and print the Key values to t...

Is there a simple way to alphabetize a String Enumeration in Java?

Just as the title says. I tried messing around a bit with Collections.sort() on a List[] and the .sort() function of an ArrayList but I was never able to parse it back to an Enumeration. Thanks! EDIT: Here's some pseduocode and further explanation. My goal is to take the keys() from a Hashtable and do complex operations involving eac...

In Eclipse Websphere 7, how do I resolve "Enumeration cannot be resolved" error message?

I would usually get this message when I was importing or creating a new project. Everything would build fine but the compiler would give me a "Enumeration cannot be resolved" error for all Enum classes/objects. I resolved this by changing compliance from Java 5 to Java 1.4, since Enumeration was added in Java 5 which was not there in Ja...

Hibernate - How to use an Enumeration as Map's Key

Hi all, My entity defines a field like Map<String, String> props; I've got this hibernate xml configuration <map name="props" table="PROPS"> <key column="id"/> <index column="name" type="string"/> <element column="value" type="string"/> </map> Now I want my Map to be an EnumMap like Map<MyEnum, String> prop...

Why cant we change Values of a dictionary while enumerating its keys?

class Program { static void Main(string[] args) { var dictionary = new Dictionary<string, int>() { {"1", 1}, {"2", 2}, {"3", 3} }; foreach (var s in dictionary.Keys) { // Throws the "Collection was modified exception..." on th...

Discovering the class where a property is first published with multiple levels of inheritence.

Using the Typinfo unit, it is easy to enumerate properties as seen in the following snippet: procedure TYRPropertiesMap.InitFrom(AClass: TClass; InheritLevel: Integer = 0); var propInfo: PPropInfo; propCount: Integer; propList: PPropList; propType: PPTypeInfo; pm: TYRPropertyMap; classInfo: TClassInfo; ix: Integer; begin ...

working pattern of yield return

When i have a code block static void Main() { foreach (int i in YieldDemo.SupplyIntegers()) { Console.WriteLine("{0} is consumed by foreach iteration", i); } } class YieldDemo { public static IEnumerable<int> SupplyIntegers() { yield return 1; yield return 2; yield return 3; }...

Point of need of custom Enumerations

When reading a post some points were given without example : To implement IEnumerable / IEnumerable, you must provide an enumerator : •If the class is "wrapping" another collection, by returning the wrapped collection's enumerator. •Via an iterator using yield return. •By instantiating your own IEnumerator/IEnumerator implementatio...

Enumeration Utility Library

I'm looking for a open source library or examples for working with Enum types in .Net. In addition to the standard extensions that people use for Enums (TypeParse, etc.), I need a way to perform operations like returning the value of the Description attribute for a given enumeration value or to return a enumeration value that has a Desc...

Create an enumerator<{datatype, datatype}> from 2 enumerables?

HI. This is what I want to do: str2 = "91"; str1 = "19"; var testQuery = from c1 in str1 from c2 in str2 select new {c1, c2}; foreach (var enumerable in testQuery) { Console.WriteLine(enumerable.c1 + " | " + enumerable.c2); } What I want: 9 | 1 1 | 9 What I re...

Powershell: Output object[] to a file

I would like to retrieve the contents of a file, filter and modify them and write the result back to a file. I do this: PS C:\code> "test1" >> test.txt PS C:\code> "test2" >> test.txt PS C:\code> $testContents = Get-Content test.txt PS C:\code> $newTestContents = $testContents | Select-Object {"abc -" + $_} PS C:\code> $newTestContents...

How do I import a COM object namespace/enumeration in Python?

I'm relatively new to programming/python, so I'd appreciate any help I can get. I want to save an excel file as a specific format using Excel through COM. Here is the code: import win32com.client as win32 def excel(): app = 'Excel' x1 = win32.gencache.EnsureDispatch('%s.Application' % app) ss = x1.Workbooks.Add() sh...

How to conver a string to a enum of type int?

I have an enum of type int: public enum BlahType { blah1 = 1, blah2 = 2 } If I have a string: string something = "blah1" How can I convert this to BlahType? ...

Scala: How to know if a class is an enumeration; isInstanceOf[Enumeration] doesn't work

I'm in scala writing a serializer that saves an object (or Model) to the database (for app engine), and I need to treat some fields as special cases. For example, if the field is of type Array[Byte], I Save it as a blob. And I need to treat Enumerations as special cases too, but I can't find out how to know if a type is an enumeration. ...

Conversion of Enum to Enumerable

To convert Enum to Enumerable ,I use public enum Flags { Trivial=1, Minor, Major, Critical } IEnumerable<int> n = Enumerable.Range((int)Flags.Trivial, (int)Flags.Critical).OfType<int>(); Just I want to know whether it is a valid conversion or not (code is working). ...

C# - AsEnumerable Example

What is the exact use of AsEnumerable? Will it change non-enumerable collection to enumerable collection?.Please give me a simple example. ...

How do I find out at runtime what area a controller is belong to in asp.net mvc?

Since this stuff is fair new I couldn't figure out any good reference on it. I want to use reflection to enumerate through all the controller in my application. This is not hard using reflection. But since area come into place. How do I know which area (if any) does a particular controller belong to? Maybe I am doing it wrong, maybe I ...

What's the meaning of the hashes at Enumerations?

I use GhostDoc for the XML-Documentation of my code, and it has a neat "auto-document"-function I use quite often, so now I used it on an enumeration and it came up with some strange hash-code I don't quite understand. What is it for? Looks sort of like this: {35A90EBF-F421-44A3-BE3A-47C72AFE47FE} ...

Relationship with Enumerated Type in Java

I'm trying to create a many-to-many relationship between two types of which one is an Enumerated type. Lets say the first model is User and the second model is Role. A user can have many roles and a role can belong to many users. I'd like to be able to write simple code like: if (user.getRoles().contains(Role.ADMIN)) { //do something...