Home All Groups Group Topic Archive Search About

Storing Enums in web.config

Author
7 Jun 2005 12:57 PM
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 ?

Author
7 Jun 2005 1:13 PM
Oenone
Matt wrote:
> 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,

--

(O)enone
Are all your drivers up to date? click for free checkup

Author
7 Jun 2005 1:45 PM
Matt
Thanks, that did it !

Matt
Show quoteHide quote
"Oenone" <oen***@nowhere.com> wrote in message
news:eEt6ZK2aFHA.3848@TK2MSFTNGP10.phx.gbl...
> Matt wrote:
> > 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,
>
> --
>
> (O)enone
>
>

Bookmark and Share