Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Sys / System / Configuration / NameValueFileSectionHandler.cs / 1 / NameValueFileSectionHandler.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System.Configuration.Internal; using System.IO; using System.Xml; using System.Runtime.Versioning; ////// /// public class NameValueFileSectionHandler : IConfigurationSectionHandler { [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] public object Create(object parent, object configContext, XmlNode section) { object result = parent; // parse XML XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file"); result = NameValueSectionHandler.CreateStatic(result, section); if (fileAttribute != null && fileAttribute.Value.Length != 0) { string filename = null; filename = fileAttribute.Value; IConfigErrorInfo configXmlNode = fileAttribute as IConfigErrorInfo; if (configXmlNode == null) { return null; } string configFile = configXmlNode.Filename; string directory = Path.GetDirectoryName(configFile); string sourceFileFullPath = Path.Combine(directory, filename); if (File.Exists(sourceFileFullPath)) { ConfigXmlDocument doc = new ConfigXmlDocument(); try { doc.Load(sourceFileFullPath); } catch (XmlException e) { throw new ConfigurationErrorsException(e.Message, e, sourceFileFullPath, e.LineNumber); } if (section.Name != doc.DocumentElement.Name) { throw new ConfigurationErrorsException( SR.GetString(SR.Config_name_value_file_section_file_invalid_root, section.Name), doc.DocumentElement); } result = NameValueSectionHandler.CreateStatic(result, doc.DocumentElement); } } return result; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ ///// This section handler allows <appSettings file="user.config" /> /// The file pointed to by the file= attribute is read as if it is /// an appSettings section in the config file. /// Note: the user.config file must have its root element match the /// section referring to it. So if appSettings has a file="user.config" /// attribute the root element in user.config must also be named appSettings. /// ///// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System.Configuration.Internal; using System.IO; using System.Xml; using System.Runtime.Versioning; ////// /// public class NameValueFileSectionHandler : IConfigurationSectionHandler { [ResourceExposure(ResourceScope.None)] [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] public object Create(object parent, object configContext, XmlNode section) { object result = parent; // parse XML XmlNode fileAttribute = section.Attributes.RemoveNamedItem("file"); result = NameValueSectionHandler.CreateStatic(result, section); if (fileAttribute != null && fileAttribute.Value.Length != 0) { string filename = null; filename = fileAttribute.Value; IConfigErrorInfo configXmlNode = fileAttribute as IConfigErrorInfo; if (configXmlNode == null) { return null; } string configFile = configXmlNode.Filename; string directory = Path.GetDirectoryName(configFile); string sourceFileFullPath = Path.Combine(directory, filename); if (File.Exists(sourceFileFullPath)) { ConfigXmlDocument doc = new ConfigXmlDocument(); try { doc.Load(sourceFileFullPath); } catch (XmlException e) { throw new ConfigurationErrorsException(e.Message, e, sourceFileFullPath, e.LineNumber); } if (section.Name != doc.DocumentElement.Name) { throw new ConfigurationErrorsException( SR.GetString(SR.Config_name_value_file_section_file_invalid_root, section.Name), doc.DocumentElement); } result = NameValueSectionHandler.CreateStatic(result, doc.DocumentElement); } } return result; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007./// This section handler allows <appSettings file="user.config" /> /// The file pointed to by the file= attribute is read as if it is /// an appSettings section in the config file. /// Note: the user.config file must have its root element match the /// section referring to it. So if appSettings has a file="user.config" /// attribute the root element in user.config must also be named appSettings. /// ///
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- CqlQuery.cs
- TrackingServices.cs
- X509AsymmetricSecurityKey.cs
- BaseAutoFormat.cs
- ToolStripMenuItemCodeDomSerializer.cs
- UInt64Storage.cs
- MainMenu.cs
- ToolStripTextBox.cs
- DesignerActionPanel.cs
- BehaviorEditorPart.cs
- DataListItemCollection.cs
- ThrowHelper.cs
- AccessKeyManager.cs
- List.cs
- BaseEntityWrapper.cs
- ModuleBuilder.cs
- RoleGroupCollection.cs
- ActivityTypeDesigner.xaml.cs
- X509ThumbprintKeyIdentifierClause.cs
- ErrorLog.cs
- AuthenticatedStream.cs
- _LocalDataStore.cs
- BooleanFacetDescriptionElement.cs
- AtomPub10CategoriesDocumentFormatter.cs
- SiblingIterators.cs
- _SslStream.cs
- MethodBody.cs
- DbConnectionPoolGroup.cs
- EmptyQuery.cs
- ReadOnlyDataSource.cs
- GenericEnumConverter.cs
- SiteMapNode.cs
- FaultConverter.cs
- StringInfo.cs
- LineBreakRecord.cs
- DetailsViewUpdateEventArgs.cs
- SafePointer.cs
- SqlBulkCopyColumnMappingCollection.cs
- UrlMappingCollection.cs
- FtpRequestCacheValidator.cs
- QueryProcessor.cs
- LinearGradientBrush.cs
- DataExpression.cs
- DependencyObjectPropertyDescriptor.cs
- RangeBaseAutomationPeer.cs
- Message.cs
- TreeSet.cs
- ProfileModule.cs
- LockCookie.cs
- FixedFlowMap.cs
- Mappings.cs
- LinearKeyFrames.cs
- ReadWriteObjectLock.cs
- IconEditor.cs
- MatchingStyle.cs
- HttpCachePolicy.cs
- DesignerActionItemCollection.cs
- Privilege.cs
- LinkLabelLinkClickedEvent.cs
- ConfigurationSchemaErrors.cs
- TcpTransportManager.cs
- DescendantQuery.cs
- FormViewUpdatedEventArgs.cs
- BuildProvider.cs
- CatalogPartCollection.cs
- ServicesSection.cs
- SelectionPatternIdentifiers.cs
- QueryExtender.cs
- ObjectItemCollectionAssemblyCacheEntry.cs
- hresults.cs
- EventLogEntryCollection.cs
- _RequestCacheProtocol.cs
- FieldValue.cs
- AccessDataSourceView.cs
- PreviewPrintController.cs
- ControlCollection.cs
- DocumentPageHost.cs
- SemanticKeyElement.cs
- HttpInputStream.cs
- SmtpFailedRecipientException.cs
- SafeProcessHandle.cs
- PackageStore.cs
- SortDescriptionCollection.cs
- XmlSerializerFactory.cs
- FieldTemplateUserControl.cs
- UnregisterInfo.cs
- ComplexPropertyEntry.cs
- ToolStripHighContrastRenderer.cs
- _TimerThread.cs
- XmlNodeList.cs
- CodeTypeOfExpression.cs
- ByteKeyFrameCollection.cs
- TableSectionStyle.cs
- ErrorProvider.cs
- SQLDoubleStorage.cs
- DbProviderFactory.cs
- CLRBindingWorker.cs
- FileUtil.cs
- BindingList.cs
- M3DUtil.cs