Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Sys / System / Configuration / NameValueFileSectionHandler.cs / 1305376 / 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
- HierarchicalDataTemplate.cs
- ArcSegment.cs
- ApplicationServiceHelper.cs
- MailAddress.cs
- XslAst.cs
- util.cs
- CompressedStack.cs
- DataTemplateSelector.cs
- Positioning.cs
- CodeAttributeDeclarationCollection.cs
- SafeBitVector32.cs
- WorkingDirectoryEditor.cs
- ExtendedProtectionPolicy.cs
- RuntimeCompatibilityAttribute.cs
- ScriptResourceHandler.cs
- WorkflowEnvironment.cs
- ArrayTypeMismatchException.cs
- AssemblyResourceLoader.cs
- EnumDataContract.cs
- MaskedTextBox.cs
- InternalConfigRoot.cs
- SystemUdpStatistics.cs
- FlowDocumentView.cs
- RequestSecurityToken.cs
- PingReply.cs
- ReflectionServiceProvider.cs
- ElementHostPropertyMap.cs
- SizeValueSerializer.cs
- CacheHelper.cs
- EntityType.cs
- DefaultAsyncDataDispatcher.cs
- Profiler.cs
- TextRange.cs
- TemplatedMailWebEventProvider.cs
- RequestNavigateEventArgs.cs
- ChtmlTextWriter.cs
- XPathChildIterator.cs
- AnnotationObservableCollection.cs
- DataSourceControlBuilder.cs
- TraceListeners.cs
- DesignerImageAdapter.cs
- AsyncResult.cs
- HttpPostedFile.cs
- AttributeProviderAttribute.cs
- MetadataItemEmitter.cs
- sitestring.cs
- UserControl.cs
- ExtendedProperty.cs
- EqualityComparer.cs
- Query.cs
- Run.cs
- TextEditorDragDrop.cs
- DataFormats.cs
- LogWriteRestartAreaState.cs
- MediaCommands.cs
- EntitySqlException.cs
- WebPartMinimizeVerb.cs
- XmlSchemaSet.cs
- RegexCode.cs
- BitStack.cs
- PngBitmapDecoder.cs
- ClipboardProcessor.cs
- WSSecurityOneDotOneSendSecurityHeader.cs
- DataTransferEventArgs.cs
- DbConnectionPoolIdentity.cs
- CodePageUtils.cs
- METAHEADER.cs
- wgx_sdk_version.cs
- InteropAutomationProvider.cs
- FrameworkContentElement.cs
- NonBatchDirectoryCompiler.cs
- DbExpressionRules.cs
- ClientType.cs
- MethodRental.cs
- HtmlTableCell.cs
- FixedSOMContainer.cs
- DiffuseMaterial.cs
- State.cs
- DataGridViewCellContextMenuStripNeededEventArgs.cs
- KeysConverter.cs
- WebHttpDispatchOperationSelector.cs
- DuplicateMessageDetector.cs
- IntranetCredentialPolicy.cs
- MILUtilities.cs
- SafeNativeMethods.cs
- PathSegment.cs
- ThreadExceptionDialog.cs
- FrameworkRichTextComposition.cs
- _RequestCacheProtocol.cs
- Attributes.cs
- CollectionsUtil.cs
- ScrollBarRenderer.cs
- ItemContainerGenerator.cs
- Duration.cs
- ContentPlaceHolderDesigner.cs
- ArrayWithOffset.cs
- SoapAttributeOverrides.cs
- RowToFieldTransformer.cs
- CellParaClient.cs
- DtdParser.cs