Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- VScrollProperties.cs
- ParserContext.cs
- BaseCAMarshaler.cs
- TreeNodeClickEventArgs.cs
- MailBnfHelper.cs
- XamlReaderConstants.cs
- FrameworkRichTextComposition.cs
- DocumentSchemaValidator.cs
- TreeWalkHelper.cs
- ServiceParser.cs
- InstanceDescriptor.cs
- HttpResponse.cs
- LicFileLicenseProvider.cs
- GZipDecoder.cs
- RootDesignerSerializerAttribute.cs
- CapabilitiesState.cs
- Variant.cs
- StructuredTypeEmitter.cs
- MarginsConverter.cs
- EDesignUtil.cs
- WebControlsSection.cs
- EntityDataSourceViewSchema.cs
- UTF32Encoding.cs
- ActivationArguments.cs
- BamlCollectionHolder.cs
- NullableDecimalMinMaxAggregationOperator.cs
- X509CertificateInitiatorClientCredential.cs
- EventDescriptor.cs
- Message.cs
- AttributeProviderAttribute.cs
- XmlDocumentSerializer.cs
- BindingCollection.cs
- GenericWebPart.cs
- HttpRuntimeSection.cs
- SafeCryptoHandles.cs
- TreeNode.cs
- ValueTypeFixupInfo.cs
- WindowsFont.cs
- RotateTransform.cs
- ChannelSinkStacks.cs
- ConversionValidationRule.cs
- EncoderParameters.cs
- PathFigureCollection.cs
- PingReply.cs
- filewebrequest.cs
- StateValidator.cs
- ClosableStream.cs
- MappingException.cs
- Button.cs
- ExpressionWriter.cs
- PageCodeDomTreeGenerator.cs
- DPAPIProtectedConfigurationProvider.cs
- GridViewCommandEventArgs.cs
- AggregateNode.cs
- GPPOINT.cs
- DocumentViewerAutomationPeer.cs
- RadioButtonBaseAdapter.cs
- DataGridCellsPresenter.cs
- ExternalException.cs
- Selection.cs
- LineServicesCallbacks.cs
- ComponentEditorForm.cs
- CodeThrowExceptionStatement.cs
- ObjectComplexPropertyMapping.cs
- WebPartConnectionsConnectVerb.cs
- WebPartTransformer.cs
- DataBinding.cs
- GeneralTransform3DGroup.cs
- WindowsGraphicsWrapper.cs
- PlanCompilerUtil.cs
- TitleStyle.cs
- Main.cs
- ToolStripPanelCell.cs
- FieldDescriptor.cs
- BatchWriter.cs
- SequenceFullException.cs
- BindingGraph.cs
- DrawingCollection.cs
- ExtensionWindow.cs
- serverconfig.cs
- RepeatBehavior.cs
- RouteCollection.cs
- ColumnBinding.cs
- TempEnvironment.cs
- SiteMapPathDesigner.cs
- Delegate.cs
- RunInstallerAttribute.cs
- MSAAEventDispatcher.cs
- MbpInfo.cs
- MarginsConverter.cs
- DeferredTextReference.cs
- PageCatalogPart.cs
- InputEventArgs.cs
- CmsInterop.cs
- InvokeProviderWrapper.cs
- SizeF.cs
- AudioFileOut.cs
- DbDataReader.cs
- DataGridViewRowPostPaintEventArgs.cs
- RangeContentEnumerator.cs