Adventures of a wannabe geek!

Ranting within

Enum String Value With JQuery Mobile

A while back I had to use JQuery mobile for a project. The project needed to have 2 themes on an application and the configuration would need to tell the application what theme to load. With JQuery Mobile, the theme string could only be a single letter. I like keeping to decent and meaningful naming conventions, so I created a configuration setting as follows:

<add key=”Theme” value=”Plain” />

I could see easily that the theme for this build of the application is the Plain theme. How could I relate that back to a JQuery theme? Plain would not be acceptable with JQuery Mobile. Therefore I had to do something different. I was able to use an attribute on the Theme Enum:

I then overrode the WebViewPage to include logic to get the Theme as follows:

As you can see, I have an extension method in place to get the string value of the enum. This then taps back into my String attribute as follows:

This then allowed me to turn a simple readable string from a web.config, into something that JQuery Mobile could understand and parse as normal