GetTypeWithReflectionPermission() приватный Метод

private GetTypeWithReflectionPermission ( IInternalConfigHost host, string typeString, bool throwOnError ) : Type
host IInternalConfigHost
typeString string
throwOnError bool
Результат System.Type
        internal bool IsEquivalentType(IInternalConfigHost host, string typeName)
        {
            try {
                if (_factoryTypeName == typeName)
                {
                    return(true);
                }

                Type t1, t2;

                if (host != null)
                {
                    t1 = TypeUtil.GetTypeWithReflectionPermission(host, typeName, false);
                    t2 = TypeUtil.GetTypeWithReflectionPermission(host, _factoryTypeName, false);
                }
                else
                {
                    t1 = TypeUtil.GetTypeWithReflectionPermission(typeName, false);
                    t2 = TypeUtil.GetTypeWithReflectionPermission(_factoryTypeName, false);
                }

                return((t1 != null) && (t1 == t2));
            }
            catch {
            }

            return(false);
        }
        public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data)
        {
            Type result = TypeUtil.GetTypeWithReflectionPermission((string)data, false);

            if (result == null)
            {
                throw new ArgumentException(SR.GetString(SR.Type_cannot_be_resolved, (string)data));
            }

            return(result);
        }
Пример #3
0
        private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn)
        {
            Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true);

            if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t))
            {
                throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider));
            }

            if (!TypeUtil.IsTypeAllowedInConfig(t))
            {
                throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName));
            }

            return(CreateAndInitializeProviderWithAssert(t, pn));
        }
        private ConfigurationBuilder InstantiateBuilder(ProviderSettings ps)
        {
            Type t = TypeUtil.GetTypeWithReflectionPermission(ps.Type, true);

            if (!typeof(ConfigurationBuilder).IsAssignableFrom(t))
            {
                throw new ConfigurationErrorsException("[" + ps.Name + "] - " + SR.GetString(SR.WrongType_of_config_builder));
            }

            // Needs to check APTCA bit.  See VSWhidbey 429996.
            if (!TypeUtil.IsTypeAllowedInConfig(t))
            {
                throw new ConfigurationErrorsException("[" + ps.Name + "] - " + SR.GetString(SR.Type_from_untrusted_assembly, t.FullName));
            }

            // Needs to check Assert Fulltrust in order for runtime to work.  See VSWhidbey 429996.
            return(CreateAndInitializeBuilderWithAssert(t, ps));
        }
        private ProtectedConfigurationProvider InstantiateProvider(ProviderSettings pn)
        {
            Type t = TypeUtil.GetTypeWithReflectionPermission(pn.Type, true);

            if (!typeof(ProtectedConfigurationProvider).IsAssignableFrom(t))
            {
                throw new Exception(SR.GetString(SR.WrongType_of_Protected_provider));
            }

            // Needs to check APTCA bit.  See VSWhidbey 429996.
            if (!TypeUtil.IsTypeAllowedInConfig(t))
            {
                throw new Exception(SR.GetString(SR.Type_from_untrusted_assembly, t.FullName));
            }

            // Needs to check Assert Fulltrust in order for runtime to work.  See VSWhidbey 429996.
            return(CreateAndInitializeProviderWithAssert(t, pn));
        }
Пример #6
0
            private void Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
            {
                // Get the type of the factory
                Type type = TypeUtil.GetTypeWithReflectionPermission(configRecord.Host, factoryRecord.FactoryTypeName, true);

                // If the type is a ConfigurationSection, that's the type.
                if (typeof(ConfigurationSection).IsAssignableFrom(type))
                {
                    _sectionCtor = TypeUtil.GetConstructorWithReflectionPermission(type, typeof(ConfigurationSection), true);
                }
                else
                {
                    // Note: in v1, IConfigurationSectionHandler is in effect a factory that has a Create method
                    // that creates the real section object.

                    // throws if type does not implement IConfigurationSectionHandler
                    TypeUtil.VerifyAssignableType(typeof(IConfigurationSectionHandler), type, true);

                    // Create an instance of the handler
                    _sectionHandler = (IConfigurationSectionHandler)TypeUtil.CreateInstanceWithReflectionPermission(type);
                }
            }