Exemple #1
0
        public ConfigurationSection GetParentSection()
        {
            VerifyDesigntime();

            if (_flags[FlagIsParentSection])
            {
                throw new InvalidOperationException(SR.Config_getparentconfigurationsection_first_instance);
            }

            // if a users create a configsection with : sectionType sec  = new sectionType();
            // the config record will be null.  Return null for the parent in this case.
            ConfigurationSection ancestor = null;

            if (_configRecord != null)
            {
                ancestor = _configRecord.FindAndCloneImmediateParentSection(_configurationSection);
                if (ancestor != null)
                {
                    ancestor.SectionInformation._flags[FlagIsParentSection] = true;
                    ancestor.SetReadOnly();
                }
            }

            return(ancestor);
        }
Exemple #2
0
 private object CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
 {
     if (this._sectionCtor != null)
     {
         ConfigurationSection section = (ConfigurationSection)System.Configuration.TypeUtil.InvokeCtorWithReflectionPermission(this._sectionCtor);
         section.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord, sectionRecord);
         section.CallInit();
         ConfigurationSection parentElement = (ConfigurationSection)parentConfig;
         section.Reset(parentElement);
         if (reader != null)
         {
             section.DeserializeSection(reader);
         }
         ConfigurationErrorsException errors = section.GetErrors();
         if (errors != null)
         {
             throw errors;
         }
         section.SetReadOnly();
         section.ResetModified();
         return(section);
     }
     if (reader != null)
     {
         XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader);
         CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode);
         object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath);
         return(this._sectionHandler.Create(parentConfig, configContext, xmlNode));
     }
     return(null);
 }
Exemple #3
0
            internal object CreateSection(bool inputIsTrusted, RuntimeConfigurationRecord configRecord,
                                          FactoryRecord factoryRecord, SectionRecord sectionRecord, object parentConfig, ConfigXmlReader reader)
            {
                object config;

                if (_sectionCtor != null)
                {
                    ConfigurationSection configSection =
                        (ConfigurationSection)_sectionCtor.Invoke(null);

                    configSection.SectionInformation.SetRuntimeConfigurationInformation(configRecord, factoryRecord,
                                                                                        sectionRecord);

                    configSection.CallInit();

                    ConfigurationSection parentSection = (ConfigurationSection)parentConfig;
                    configSection.Reset(parentSection);

                    if (reader != null)
                    {
                        configSection.DeserializeSection(reader);
                    }

                    // throw if there are any cached errors
                    ConfigurationErrorsException errors = configSection.GetErrors();
                    if (errors != null)
                    {
                        throw errors;
                    }

                    // don't allow changes to sections at runtime
                    configSection.SetReadOnly();

                    // reset the modified bit
                    configSection.ResetModified();

                    config = configSection;
                }
                else
                {
                    if (reader != null)
                    {
                        XmlNode xmlNode = ErrorInfoXmlDocument.CreateSectionXmlNode(reader);

                        CheckForLockAttributes(factoryRecord.ConfigKey, xmlNode);

                        // In v1, our old section handler expects a context that contains the virtualPath from the configPath
                        object configContext = configRecord.Host.CreateDeprecatedConfigContext(configRecord.ConfigPath);

                        config = _sectionHandler.Create(parentConfig, configContext, xmlNode);
                    }
                    else
                    {
                        config = null;
                    }
                }

                return(config);
            }
Exemple #4
0
        public ConfigurationSection GetParentSection()
        {
            this.VerifyDesigntime();
            if (this._flags[0x200])
            {
                throw new InvalidOperationException(System.Configuration.SR.GetString("Config_getparentconfigurationsection_first_instance"));
            }
            ConfigurationSection section = null;

            if (this._configRecord != null)
            {
                section = this._configRecord.FindAndCloneImmediateParentSection(this._configurationSection);
                if (section != null)
                {
                    section.SectionInformation._flags[0x200] = true;
                    section.SetReadOnly();
                }
            }
            return(section);
        }