CommunityServer中的反射

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;
        }
posted @ 2005-09-28 11:02  烈马狂生  阅读(243)  评论(0编辑  收藏  举报