Question

I'm working on a semantic web application in which assembly of an ontology is beeing used. I used Rowlex OWLGrinder for converting OWL to assembly.

In the ontology there are some classes having individuals, which are converted tp Enum classes containing some constants in .dll assemblies. For example an OWL class named Language with an individual named English, will be converted to a class named Language containing English constant. The Language.English is a string, containing the URI specified for the individual in the ontology.

alt text http://img5.imageshack.us/img5/9308/73263054.jpg alt text http://img5.imageshack.us/img5/2246/11461238.jpg

I this context I can not find a way to cycle between enum class constants. For example using something like this:

    foreach (string item in Enum.GetNames(typeof(Language)))
    {

    }

this code throws an exception saying that Language isn't an Enum.

I was wondering if anyone would help me in this problem.

Was it helpful?

Solution

As the error says, it's not a real enum.

It sounds like you need reflection:

var fields = typeof(Language).GetFields(BindingFlags.Static 
                                        | BindingFlags.Public);
foreach (string item in fields.Select(field => field.GetValue(null)))
{
     // ...
}

That's assuming there are no other public static fields in the type. You could always filter by type etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top