|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Storing Enums in web.configI 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 ? Matt wrote:
> When I try to assign myEnum = System.Config... I get an error message Try something along these lines:> as I cannot convert myEnum to a string. \\\ 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 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 > >
Other interesting topics
ASP.NET image - remove border attribute (c#)
Httphandler redirection to document -- GetCompiledPageInstance dropdowncontrol problem trying to show images in the grid Page Expired Warning Project in modules Instantiate UserControl without LoadControl Restarting IIS after installation of a new Webapplication Time out issue to connect to Sql server Get Previous URL |
|||||||||||||||||||||||