1.反射
private
static
void
CreateDefaultCommonProvider()
{ // Get the names of the providers // CSConfiguration config = CSConfiguration.GetConfig(); // Read the configuration specific information // for this provider // Provider sqlForumsProvider = (Provider) config.Providers[ForumDataProviderName]; // Read the connection string for this provider // _defaultInstance = DataProviders.CreateInstance(sqlForumsProvider) as ForumDataProvider; }
public
static
object
CreateInstance(Provider dataProvider)
{ //Find the current attributes string connectionString = null; //dataProvider.Attributes["connectionString"]; string databaseOwner = null;// dataProvider.Attributes["databaseOwner"]; GetDataStoreParameters(dataProvider, out connectionString, out databaseOwner); //Get the type Type type = Type.GetType(dataProvider.Type); object newObject = null; if(type != null) { newObject = Activator.CreateInstance(type,new object[]{databaseOwner,connectionString}); } if(newObject == null) //If we can not create an instance, throw an exception ProviderException(dataProvider.Name); return newObject; }
转载于:https://www.cnblogs.com/Elong/archive/2005/09/28/245713.html
相关资源:JAVA上百实例源码以及开源项目
转载请注明原文地址: https://mac.8miu.com/read-79589.html