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
- XPathDocumentBuilder.cs
- DataGridViewCellValueEventArgs.cs
- ResourcePool.cs
- TextTreePropertyUndoUnit.cs
- DiscoveryDocument.cs
- FamilyTypeface.cs
- XmlQueryCardinality.cs
- SqlWebEventProvider.cs
- HtmlTextArea.cs
- DataGridViewColumnTypeEditor.cs
- ScriptResourceAttribute.cs
- Quack.cs
- ListSortDescriptionCollection.cs
- Zone.cs
- ResourceDictionaryCollection.cs
- RelationshipConverter.cs
- EntityDataSourceContextCreatingEventArgs.cs
- OnOperation.cs
- HitTestWithPointDrawingContextWalker.cs
- RSAOAEPKeyExchangeFormatter.cs
- GatewayDefinition.cs
- __FastResourceComparer.cs
- FlowDocumentFormatter.cs
- FreezableOperations.cs
- WinOEToolBoxItem.cs
- PaperSize.cs
- ItemCollection.cs
- WinFormsComponentEditor.cs
- ImageMapEventArgs.cs
- XsltCompileContext.cs
- TemplatedAdorner.cs
- Padding.cs
- SizeAnimation.cs
- TranslateTransform3D.cs
- ViewKeyConstraint.cs
- FactoryRecord.cs
- SmtpException.cs
- BoundingRectTracker.cs
- HtmlTableRowCollection.cs
- ChildTable.cs
- ImmComposition.cs
- Function.cs
- CodeAssignStatement.cs
- AsymmetricSecurityProtocolFactory.cs
- ContentValidator.cs
- TextBoxAutoCompleteSourceConverter.cs
- DbXmlEnabledProviderManifest.cs
- SchemaInfo.cs
- FileEnumerator.cs
- ConfigurationSection.cs
- TreeViewItem.cs
- SecurityPolicySection.cs
- ReadContentAsBinaryHelper.cs
- RSAOAEPKeyExchangeDeformatter.cs
- CodeMethodMap.cs
- InternalBufferOverflowException.cs
- CookieProtection.cs
- TextServicesManager.cs
- Tag.cs
- RetrieveVirtualItemEventArgs.cs
- ProtocolException.cs
- File.cs
- DataGridItemEventArgs.cs
- SystemIcmpV4Statistics.cs
- HebrewCalendar.cs
- ReadWriteObjectLock.cs
- Span.cs
- ResXResourceSet.cs
- PointCollectionConverter.cs
- MachinePropertyVariants.cs
- ToolStripSeparatorRenderEventArgs.cs
- DataGridCaption.cs
- ResourceBinder.cs
- AjaxFrameworkAssemblyAttribute.cs
- ExpressionWriter.cs
- XhtmlCssHandler.cs
- Link.cs
- SqlDataSource.cs
- CodeNamespaceImport.cs
- DataSourceHelper.cs
- OletxVolatileEnlistment.cs
- ResourceAttributes.cs
- xamlnodes.cs
- MediaScriptCommandRoutedEventArgs.cs
- UpDownEvent.cs
- ChainOfDependencies.cs
- ButtonBaseAdapter.cs
- NetworkStream.cs
- Gdiplus.cs
- WebCodeGenerator.cs
- SqlTypeSystemProvider.cs
- AddValidationError.cs
- InstalledVoice.cs
- StringStorage.cs
- SelectionRange.cs
- HttpDebugHandler.cs
- ProcessModelInfo.cs
- SecureEnvironment.cs
- DrawItemEvent.cs
- TimeSpan.cs