Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The Language class is not an enum in C# terminology. It is an ordinary class with public const string fields. ROWLEX intentionally generates enum-imitating-classes instead of native enums for 2 reasons:</p> <ol> <li>The value of an native C# enum is an integer, while a public const string field can take the URI of the OWL class instance.</li> <li>The class can have one additional public static string that is "URI" which represents the class URI consistently for every single ROWLEX generated class.</li> </ol> <p>That was the background. If I understood your question right, you had an issue binding the selected name displayed in the dropdown back to the URI, and you wanted to use the position of the element inside the array you created. I would not do it that way. DropDownLists typically have both ID and Value fields for every list item (can be named differently component to component). The ID is expected to be a unique object while the Value is expected to contain something human readable. Set the ID with URI of the "enum" field, and the Value as you have done. So this is how you populate your dropdown:</p> <pre><code>System.Reflection.FieldInfo[] resLanFields = typeof(Language).GetFields(); foreach(FieldInfo field in resLanFields) { ListItem item = new ListItem(); item.ID = field.GetValue(null); // takes the URI value of the const field item.Value = field.Name; // takes the name of the const field dropDownList_lang.AddItem(item); } </code></pre> <p>And when the user made his/her choice, this is how you read the result out: </p> <pre><code>learningResource.hasLanguage = (string) dropDownList_lang.SelectedItem.ID; </code></pre> <p>Since there is implicit casting operator implemented on the ROWLEX enum-imitating-class (string=>Language) you can safely set your triple subject as a string. Should compile without issue. Simple, isn't it? ;)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload