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
- UnsafeNativeMethods.cs
- ComplexTypeEmitter.cs
- WsdlBuildProvider.cs
- TreeBuilderBamlTranslator.cs
- TableItemStyle.cs
- XmlTextWriter.cs
- IsolationInterop.cs
- BaseAppDomainProtocolHandler.cs
- EntityDesignerBuildProvider.cs
- UiaCoreApi.cs
- StringComparer.cs
- XmlConvert.cs
- NumberFormatInfo.cs
- StylusShape.cs
- MostlySingletonList.cs
- SectionRecord.cs
- DataSvcMapFile.cs
- GenerateTemporaryTargetAssembly.cs
- DataGridViewSelectedColumnCollection.cs
- CommonRemoteMemoryBlock.cs
- XamlUtilities.cs
- RootProfilePropertySettingsCollection.cs
- DataSetUtil.cs
- TemplateColumn.cs
- DropDownHolder.cs
- FakeModelItemImpl.cs
- Context.cs
- PublisherMembershipCondition.cs
- ArrayElementGridEntry.cs
- GiveFeedbackEventArgs.cs
- MdImport.cs
- DataGridViewTextBoxCell.cs
- DLinqColumnProvider.cs
- MasterPageParser.cs
- Typography.cs
- HexParser.cs
- SdlChannelSink.cs
- PathData.cs
- IndexerNameAttribute.cs
- LoginView.cs
- DBAsyncResult.cs
- CurrentChangingEventArgs.cs
- _BufferOffsetSize.cs
- ToolStripPanelDesigner.cs
- Encoder.cs
- Brush.cs
- RenderDataDrawingContext.cs
- HtmlInputReset.cs
- EncoderFallback.cs
- NamespaceCollection.cs
- ProviderIncompatibleException.cs
- WebFormDesignerActionService.cs
- EdmPropertyAttribute.cs
- TimeSpanStorage.cs
- CalendarAutomationPeer.cs
- PersonalizableTypeEntry.cs
- GenericQueueSurrogate.cs
- SqlParameterizer.cs
- IArgumentProvider.cs
- RequestCachePolicy.cs
- _ListenerResponseStream.cs
- HostSecurityManager.cs
- ActivityCodeDomSerializer.cs
- DecoderFallbackWithFailureFlag.cs
- COSERVERINFO.cs
- RegistrySecurity.cs
- BitmapCodecInfo.cs
- Latin1Encoding.cs
- Splitter.cs
- TransformGroup.cs
- IntegerValidatorAttribute.cs
- XmlNamespaceMapping.cs
- SvcMapFileSerializer.cs
- ControlCodeDomSerializer.cs
- ValidationSummary.cs
- MemberHolder.cs
- PerformanceCounters.cs
- RangeContentEnumerator.cs
- ProxyFragment.cs
- DispatchWrapper.cs
- CaseInsensitiveComparer.cs
- _emptywebproxy.cs
- HtmlFormWrapper.cs
- EvidenceTypeDescriptor.cs
- MultiView.cs
- BinaryParser.cs
- RelativeSource.cs
- DataGridViewRowHeightInfoPushedEventArgs.cs
- XmlChildNodes.cs
- IncrementalReadDecoders.cs
- InternalException.cs
- WebRequestModuleElementCollection.cs
- xdrvalidator.cs
- DataGridViewCellParsingEventArgs.cs
- ValueConversionAttribute.cs
- MemoryMappedFileSecurity.cs
- QuotedStringFormatReader.cs
- LocalizableResourceBuilder.cs
- PathStreamGeometryContext.cs
- StreamReader.cs