Storing Enums in web.config

M

Matt

I have a module I have written that I'd like to use in a number of projets.
To save the various users having to tweak the code and recompile it, I'd
like to store all the parameters in the web.config.

This works fine apart from a series of eNums I have created.
When I try to assign myEnum = System.Config... I get an error message as I
cannot convert myEnum to a string.

So how do I do this ?
 
O

Oenone

Matt said:
When I try to assign myEnum = System.Config... I get an error message
as I cannot convert myEnum to a string.

Try something along these lines:

\\\
Dim myEnum as MyEnumType
myEnum = [Enum].Parse(GetType(MyEnumType), System.Config.whatever)
///

If you're using Option Strict, you'll need to DirectCast that to the
appropriate type:

\\\

myEnum = DirectCast([Enum].Parse(GetType(MyEnumType),
System.Config.whatever), MyEnumType)
///

Note that Enum.Parse() is case-sensitive.

Hope that helps,
 
M

Matt

Thanks, that did it !

Matt
Oenone said:
Matt said:
When I try to assign myEnum = System.Config... I get an error message
as I cannot convert myEnum to a string.

Try something along these lines:

\\\
Dim myEnum as MyEnumType
myEnum = [Enum].Parse(GetType(MyEnumType), System.Config.whatever)
///

If you're using Option Strict, you'll need to DirectCast that to the
appropriate type:

\\\

myEnum = DirectCast([Enum].Parse(GetType(MyEnumType),
System.Config.whatever), MyEnumType)
///

Note that Enum.Parse() is case-sensitive.

Hope that helps,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top