|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to instance type of configurationHi all:
I saw there is one line on configuration file as following, <add name="MyProfileProvider" connectionStringName="MyDatabase" applicationName="/" type="System.Web.Profile.SqlProfileProvider, System.Web" /> I want to know how to instance type in my code. Thanks! Best Regards Enosh Chang "Enosh Chang" <changen***@yahoo.com.tw> wrote in message I think you're asking how to create an instance of a type knowing only the news:%23Q1bvQu7GHA.3644@TK2MSFTNGP03.phx.gbl... > Hi all: > > I saw there is one line on configuration file as following, > > <add name="MyProfileProvider" > connectionStringName="MyDatabase" > applicationName="/" > type="System.Web.Profile.SqlProfileProvider, System.Web" /> > > I want to know how to instance type in my code. Thanks! name of the type. In that case: Type ty = Type.GetType( "System.Web.Profile.SqlProfileProvider, System.Web" ); System.Web.SqlProfileProvider prov = (System.Web.SqlProfileProvider)Activator.CreateInstance(ty); If that wasn't what you were looking for, post back with a more detailed question. -cd
Show quote
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam> You probably should use an interface or an abstract class here: if you're ha scritto nel messaggio news:uHXRJVu7GHA.4500@TK2MSFTNGP02.phx.gbl... >> I saw there is one line on configuration file as following, >> >> <add name="MyProfileProvider" >> connectionStringName="MyDatabase" >> applicationName="/" >> type="System.Web.Profile.SqlProfileProvider, System.Web" /> >> >> I want to know how to instance type in my code. Thanks! > > I think you're asking how to create an instance of a type knowing only the > name of the type. In that case: > > Type ty = Type.GetType( > "System.Web.Profile.SqlProfileProvider, System.Web" > ); > System.Web.SqlProfileProvider prov > = (System.Web.SqlProfileProvider)Activator.CreateInstance(ty); reading the type name from a configuration file, chanches are you just don't know the actual type of the object, so you can't give a type to "prov". Massimo "Massimo" <bar***@mclink.it> ???????:%23LFqsZu7GHA.4***@TK2MSFTNGP05.phx.gbl...Show quote > "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam> That's so great. But I encounter another problem that it displays "Could not > ha scritto nel messaggio news:uHXRJVu7GHA.4500@TK2MSFTNGP02.phx.gbl... > >>> I saw there is one line on configuration file as following, >>> >>> <add name="MyProfileProvider" >>> connectionStringName="MyDatabase" >>> applicationName="/" >>> type="System.Web.Profile.SqlProfileProvider, System.Web" /> >>> >>> I want to know how to instance type in my code. Thanks! >> >> I think you're asking how to create an instance of a type knowing only >> the name of the type. In that case: >> >> Type ty = Type.GetType( >> "System.Web.Profile.SqlProfileProvider, System.Web" >> ); >> System.Web.SqlProfileProvider prov >> = (System.Web.SqlProfileProvider)Activator.CreateInstance(ty); > > You probably should use an interface or an abstract class here: if you're > reading the type name from a configuration file, chanches are you just > don't know the actual type of the object, so you can't give a type to > "prov". > > > Massimo > load file or assembly 'XXXXX' or one of its dependencies" for some types. How to solve this problem, dynamic loading assemblies? |
|||||||||||||||||||||||