Code:
                         / Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Configuration / System / Configuration / ConfigurationSectionGroup.cs / 1 / ConfigurationSectionGroup.cs
                        
                        
                            //------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//  
//----------------------------------------------------------------------------- 
namespace System.Configuration { 
    using System; 
    using System.Configuration.Internal;
 
    public class ConfigurationSectionGroup {
        string                              _configKey              = String.Empty;
        string                              _group                  = String.Empty;
        string                              _name                   = String.Empty; 
        ConfigurationSectionCollection      _configSections;
        ConfigurationSectionGroupCollection _configSectionGroups; 
        MgmtConfigurationRecord             _configRecord; 
        string                              _typeName;
        bool                                _declared; 
        bool                                _declarationRequired;
        bool                                _isRoot;
 
        public ConfigurationSectionGroup() {
        } 
 
        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; 
            }
        } 
 
        internal void RootAttachToConfigurationRecord(MgmtConfigurationRecord configRecord) {
            _configRecord = configRecord; 
            _isRoot = true;
        }
 
        internal void DetachFromConfigurationRecord() {
            if (_configSections != null) { 
                _configSections.DetachFromConfigurationRecord(); 
            }
 
            if (_configSectionGroups != null) {
                _configSectionGroups.DetachFromConfigurationRecord();
            }
 
            _configRecord = null;
        } 
 
        internal bool Attached {
            get {return _configRecord != null;} 
        }
        private FactoryRecord FindParentFactoryRecord(bool permitErrors) {
            FactoryRecord factoryRecord = null; 
            if (_configRecord != null && !_configRecord.Parent.IsRootConfig) { 
                factoryRecord = _configRecord.Parent.FindFactoryRecord(_configKey, permitErrors); 
            }
 
            return factoryRecord;
        }
        private void VerifyIsAttachedToConfigRecord() { 
            if (_configRecord == null) {
                throw new InvalidOperationException(SR.GetString(SR.Config_cannot_edit_configurationsectiongroup_when_not_attached)); 
            } 
        }
 
        // IsDeclared
        //
        // Is the Declaration in this config file?
        // 
        public bool IsDeclared {
            get { 
                return _declared; 
            }
        } 
        // IsDeclarationRequired
        //
        // Is the Declaration Required.  It is required if it is not set 
        // int a parent, or the parent entry does not have the type
        // 
        public bool IsDeclarationRequired { 
            get {
                return _declarationRequired; 
            }
        }
        // ForceDeclaration 
        //
        // Force the declaration to be written. 
        // 
        public void ForceDeclaration() {
            ForceDeclaration(true); 
        }
        // ForceDeclaration
        // 
        // Force the declaration to be written.  If this is false, it
        // may be ignored depending on if it is Required 
        // 
        public void ForceDeclaration(bool force) {
            if (_isRoot) { 
                throw new InvalidOperationException(SR.GetString(SR.Config_root_section_group_cannot_be_edited));
            }
            if (_configRecord != null && _configRecord.IsLocationConfig) { 
                throw new InvalidOperationException(SR.GetString(SR.Config_cannot_edit_configurationsectiongroup_in_location_config));
            } 
 
            if (!force && _declarationRequired ) {
                // Since it is required, we can not remove it 
            }
            else {
                _declared = force;
            } 
        }
 
        public string SectionGroupName { 
            get {return _configKey;}
        } 
        public string Name {
            get {return _name;}
        } 
        public string Type { 
            get {return _typeName;} 
            set {
                if (_isRoot) { 
                    throw new InvalidOperationException(SR.GetString(SR.Config_root_section_group_cannot_be_edited));
                }
                // Since type is optional for a section group, allow it to be removed. 
                // Note that a typename of "" is not permitted in the config file.
                string typeName = value; 
                if (String.IsNullOrEmpty(typeName)) { 
                    typeName = null;
                } 
                if (_configRecord != null) {
                    if (_configRecord.IsLocationConfig) {
                        throw new InvalidOperationException(SR.GetString(SR.Config_cannot_edit_configurationsectiongroup_in_location_config)); 
                    }
 
                    // allow type to be different from current type, 
                    // so long as it doesn't conflict with a type already defined
                    if (typeName != null) { 
                        FactoryRecord factoryRecord = FindParentFactoryRecord(false);
                        if (factoryRecord != null && !factoryRecord.IsEquivalentType(_configRecord.Host, typeName)) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_already_defined, _configKey));
                        } 
                    }
                } 
 
                _typeName = typeName;
            } 
        }
        public ConfigurationSectionCollection Sections {
            get { 
                if (_configSections == null) {
                    VerifyIsAttachedToConfigRecord(); 
                    _configSections = new ConfigurationSectionCollection(_configRecord, this); 
                }
 
                return _configSections;
            }
        }
 
        public ConfigurationSectionGroupCollection SectionGroups {
            get { 
                if (_configSectionGroups == null) { 
                    VerifyIsAttachedToConfigRecord();
                    _configSectionGroups = new ConfigurationSectionGroupCollection(_configRecord, this); 
                }
                return _configSectionGroups;
            } 
        }
 
        internal bool IsRoot { 
            get {return _isRoot;}
        } 
    }
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------ 
// 
//     Copyright (c) Microsoft Corporation.  All rights reserved.
//  
//----------------------------------------------------------------------------- 
namespace System.Configuration { 
    using System; 
    using System.Configuration.Internal;
 
    public class ConfigurationSectionGroup {
        string                              _configKey              = String.Empty;
        string                              _group                  = String.Empty;
        string                              _name                   = String.Empty; 
        ConfigurationSectionCollection      _configSections;
        ConfigurationSectionGroupCollection _configSectionGroups; 
        MgmtConfigurationRecord             _configRecord; 
        string                              _typeName;
        bool                                _declared; 
        bool                                _declarationRequired;
        bool                                _isRoot;
 
        public ConfigurationSectionGroup() {
        } 
 
        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; 
            }
        } 
 
        internal void RootAttachToConfigurationRecord(MgmtConfigurationRecord configRecord) {
            _configRecord = configRecord; 
            _isRoot = true;
        }
 
        internal void DetachFromConfigurationRecord() {
            if (_configSections != null) { 
                _configSections.DetachFromConfigurationRecord(); 
            }
 
            if (_configSectionGroups != null) {
                _configSectionGroups.DetachFromConfigurationRecord();
            }
 
            _configRecord = null;
        } 
 
        internal bool Attached {
            get {return _configRecord != null;} 
        }
        private FactoryRecord FindParentFactoryRecord(bool permitErrors) {
            FactoryRecord factoryRecord = null; 
            if (_configRecord != null && !_configRecord.Parent.IsRootConfig) { 
                factoryRecord = _configRecord.Parent.FindFactoryRecord(_configKey, permitErrors); 
            }
 
            return factoryRecord;
        }
        private void VerifyIsAttachedToConfigRecord() { 
            if (_configRecord == null) {
                throw new InvalidOperationException(SR.GetString(SR.Config_cannot_edit_configurationsectiongroup_when_not_attached)); 
            } 
        }
 
        // IsDeclared
        //
        // Is the Declaration in this config file?
        // 
        public bool IsDeclared {
            get { 
                return _declared; 
            }
        } 
        // IsDeclarationRequired
        //
        // Is the Declaration Required.  It is required if it is not set 
        // int a parent, or the parent entry does not have the type
        // 
        public bool IsDeclarationRequired { 
            get {
                return _declarationRequired; 
            }
        }
        // ForceDeclaration 
        //
        // Force the declaration to be written. 
        // 
        public void ForceDeclaration() {
            ForceDeclaration(true); 
        }
        // ForceDeclaration
        // 
        // Force the declaration to be written.  If this is false, it
        // may be ignored depending on if it is Required 
        // 
        public void ForceDeclaration(bool force) {
            if (_isRoot) { 
                throw new InvalidOperationException(SR.GetString(SR.Config_root_section_group_cannot_be_edited));
            }
            if (_configRecord != null && _configRecord.IsLocationConfig) { 
                throw new InvalidOperationException(SR.GetString(SR.Config_cannot_edit_configurationsectiongroup_in_location_config));
            } 
 
            if (!force && _declarationRequired ) {
                // Since it is required, we can not remove it 
            }
            else {
                _declared = force;
            } 
        }
 
        public string SectionGroupName { 
            get {return _configKey;}
        } 
        public string Name {
            get {return _name;}
        } 
        public string Type { 
            get {return _typeName;} 
            set {
                if (_isRoot) { 
                    throw new InvalidOperationException(SR.GetString(SR.Config_root_section_group_cannot_be_edited));
                }
                // Since type is optional for a section group, allow it to be removed. 
                // Note that a typename of "" is not permitted in the config file.
                string typeName = value; 
                if (String.IsNullOrEmpty(typeName)) { 
                    typeName = null;
                } 
                if (_configRecord != null) {
                    if (_configRecord.IsLocationConfig) {
                        throw new InvalidOperationException(SR.GetString(SR.Config_cannot_edit_configurationsectiongroup_in_location_config)); 
                    }
 
                    // allow type to be different from current type, 
                    // so long as it doesn't conflict with a type already defined
                    if (typeName != null) { 
                        FactoryRecord factoryRecord = FindParentFactoryRecord(false);
                        if (factoryRecord != null && !factoryRecord.IsEquivalentType(_configRecord.Host, typeName)) {
                            throw new ConfigurationErrorsException(SR.GetString(SR.Config_tag_name_already_defined, _configKey));
                        } 
                    }
                } 
 
                _typeName = typeName;
            } 
        }
        public ConfigurationSectionCollection Sections {
            get { 
                if (_configSections == null) {
                    VerifyIsAttachedToConfigRecord(); 
                    _configSections = new ConfigurationSectionCollection(_configRecord, this); 
                }
 
                return _configSections;
            }
        }
 
        public ConfigurationSectionGroupCollection SectionGroups {
            get { 
                if (_configSectionGroups == null) { 
                    VerifyIsAttachedToConfigRecord();
                    _configSectionGroups = new ConfigurationSectionGroupCollection(_configRecord, this); 
                }
                return _configSectionGroups;
            } 
        }
 
        internal bool IsRoot { 
            get {return _isRoot;}
        } 
    }
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
                        
                        
                        
                        
                    Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- X509ChainPolicy.cs
- WebPermission.cs
- ObjectDataSourceSelectingEventArgs.cs
- AdRotator.cs
- DataRecordInternal.cs
- EntitySqlQueryCacheEntry.cs
- SortDescription.cs
- OperationCanceledException.cs
- MemoryFailPoint.cs
- CaseCqlBlock.cs
- Win32PrintDialog.cs
- ModelToObjectValueConverter.cs
- DockAndAnchorLayout.cs
- UriPrefixTable.cs
- ConfigurationManagerHelperFactory.cs
- DataControlExtensions.cs
- CompressStream.cs
- PKCS1MaskGenerationMethod.cs
- ButtonBase.cs
- MemberHolder.cs
- ObjectDisposedException.cs
- URLAttribute.cs
- webbrowsersite.cs
- ResourceWriter.cs
- SqlCacheDependencyDatabase.cs
- BinaryWriter.cs
- RealizationContext.cs
- AddInSegmentDirectoryNotFoundException.cs
- ConfigurationLocation.cs
- ServiceContractListItem.cs
- Propagator.cs
- GlyphInfoList.cs
- AudioFormatConverter.cs
- DefaultPrintController.cs
- ImageMap.cs
- QilXmlReader.cs
- AtomMaterializerLog.cs
- GraphicsPath.cs
- SocketAddress.cs
- SchemaTableColumn.cs
- Zone.cs
- NoneExcludedImageIndexConverter.cs
- ArrayWithOffset.cs
- TextContainer.cs
- PartialList.cs
- Preprocessor.cs
- RSAPKCS1KeyExchangeFormatter.cs
- KnownTypes.cs
- _Rfc2616CacheValidators.cs
- DbDataAdapter.cs
- UserControl.cs
- CodeSnippetCompileUnit.cs
- Pair.cs
- RowCache.cs
- XhtmlTextWriter.cs
- MetadataSerializer.cs
- OleDbWrapper.cs
- StrokeCollection2.cs
- InlineCollection.cs
- AssertFilter.cs
- Tile.cs
- SimpleType.cs
- Model3DCollection.cs
- DesignerView.xaml.cs
- XmlJsonReader.cs
- HostSecurityManager.cs
- XNodeSchemaApplier.cs
- QilName.cs
- FrameworkReadOnlyPropertyMetadata.cs
- DependencyProperty.cs
- XPathItem.cs
- MailHeaderInfo.cs
- SqlDataSourceFilteringEventArgs.cs
- CodeDomExtensionMethods.cs
- DomainConstraint.cs
- ResponseBodyWriter.cs
- MultiPropertyDescriptorGridEntry.cs
- httpserverutility.cs
- TypeConverterAttribute.cs
- WebCategoryAttribute.cs
- FontInfo.cs
- XmlObjectSerializerReadContextComplexJson.cs
- PageEventArgs.cs
- unitconverter.cs
- ControlCachePolicy.cs
- Visitor.cs
- ProxyWebPartManager.cs
- ObjectDataSourceEventArgs.cs
- CodeArgumentReferenceExpression.cs
- ErrorEventArgs.cs
- ProfileBuildProvider.cs
- unsafenativemethodsother.cs
- TemplatePartAttribute.cs
- DBAsyncResult.cs
- SingleKeyFrameCollection.cs
- ColumnWidthChangingEvent.cs
- DataSourceConverter.cs
- MouseGestureValueSerializer.cs
- Run.cs
- _HeaderInfoTable.cs