System.Configuration.ConfigurationSectionGroup.AttachToConfigurationRecord C# (CSharp) Метод

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

private AttachToConfigurationRecord ( MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord ) : void
configRecord MgmtConfigurationRecord
factoryRecord FactoryRecord
Результат void
        internal void AttachToConfigurationRecord(MgmtConfigurationRecord configRecord, FactoryRecord factoryRecord) {
            _configRecord = configRecord;
            _configKey = factoryRecord.ConfigKey;
            _group = factoryRecord.Group;
            _name = factoryRecord.Name;
            _typeName = factoryRecord.FactoryTypeName;

            if (_typeName != null) {
                 FactoryRecord parentFactoryRecord = null;
                 if (!configRecord.Parent.IsRootConfig) {
                     parentFactoryRecord = configRecord.Parent.FindFactoryRecord(factoryRecord.ConfigKey, true);
                 }
                 
                 _declarationRequired = (parentFactoryRecord == null || parentFactoryRecord.FactoryTypeName == null);
                 _declared            = configRecord.GetFactoryRecord(factoryRecord.ConfigKey, true) != null;
            }
        }

Usage Example

        //
        // Add a new configuration section group to this config file.
        //
        // Called from ConfigurationSectionGroupCollection.Add().
        // Note this method DOES NOT update the associated ConfigurationSectionGroupCollection.
        //
        internal void AddConfigurationSectionGroup(string group, string name, ConfigurationSectionGroup configSectionGroup) {
            // <location> tags can't have a <configSections> declaration.
            if (IsLocationConfig) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsectiongroup_in_location_config));
            }

            // Validate name argument.
            VerifySectionName(name, null, false);

            // Validate configSectionGroup argument.
            if (configSectionGroup == null) {
                throw ExceptionUtil.ParameterInvalid("name");
            }

            // A section group can only belong to one section group collection.
            if (configSectionGroup.Attached) {
                throw new InvalidOperationException(SR.GetString(SR.Config_add_configurationsectiongroup_already_added));
            }

            string configKey = BaseConfigurationRecord.CombineConfigKey(group, name);

            // Do not add if the section group already exists, even if it is of a different type.
            FactoryRecord factoryRecord = FindFactoryRecord(configKey, true);
            if (factoryRecord != null) {
                throw new ArgumentException(SR.GetString(SR.Config_add_configurationsectiongroup_already_exists));
            }

            // Add to list of all section groups.
            if (_sectionGroupFactories != null) {
                _sectionGroupFactories.Add(configKey, new FactoryId(configKey, group, name));
            }

            // Get the type name - if it is not specified explicitly, get it from the type of the object.
            string typeName = configSectionGroup.Type;
            if (typeName == null) {
                typeName = Host.GetConfigTypeName(configSectionGroup.GetType());
            }

            // Create a factory record and add it to the collection of factory records.
            factoryRecord = new FactoryRecord(configKey, group, name, typeName, ConfigStreamInfo.StreamName, -1);
            EnsureFactories()[configKey] = factoryRecord;

            // Add it to list of evaluated configuration section groups.
            SectionGroups[configKey] = configSectionGroup;

            // Remove it from RemovedSectionGroups if it was previously removed.
            if (_removedSectionGroups != null) {
                _removedSectionGroups.Remove(configKey);
            }

            // Attach to the configuration record.
            configSectionGroup.AttachToConfigurationRecord(this, factoryRecord);
        }
All Usage Examples Of System.Configuration.ConfigurationSectionGroup::AttachToConfigurationRecord