Ejemplo n.º 1
0
        private static T CreateInstance <T>(string typeName) where T : class
        {
            Type type = Type.GetType(typeName);

            if (type == null)
            {
                throw new ConfigurationErrorsException(string.Format("无法加载类型 {0}", typeName));
            }

            T provider = SecureUtil.SecureCreateInstance(type, null, true) as T;

            if (provider == null)
            {
                throw new ConfigurationErrorsException(string.Format("未能创建类型 {0}", typeName));
            }

            return(provider);
        }
Ejemplo n.º 2
0
        private static ProviderBase CreateProvider(string name, string providerTypeName, NameValueCollection parameters)
        {
            Type type = Type.GetType(providerTypeName);

            if (type == null)
            {
                throw new ConfigurationErrorsException(string.Format("无法加载提供程序类型 {0}", providerTypeName));
            }


            ProviderBase provider = SecureUtil.SecureCreateInstance(type, null, true) as ProviderBase;

            if (provider == null)
            {
                throw new ConfigurationErrorsException(string.Format("未能创建提供程序类型 {0}", providerTypeName));
            }

            NameValueCollection copy = new NameValueCollection(parameters);

            provider.Initialize(name, copy);

            return(provider);
        }