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
- ComplexObject.cs
- PageTrueTypeFont.cs
- Internal.cs
- XmlSchemaSimpleContentExtension.cs
- WebBrowserBase.cs
- StrongNameUtility.cs
- EntitySetBase.cs
- PropertyGridCommands.cs
- SmiMetaData.cs
- BlobPersonalizationState.cs
- followingquery.cs
- CloudCollection.cs
- TargetPerspective.cs
- DropDownList.cs
- WebConfigurationHostFileChange.cs
- RelationshipConverter.cs
- ListViewAutomationPeer.cs
- ConnectionsZoneAutoFormat.cs
- ResourceCodeDomSerializer.cs
- FileInfo.cs
- GridViewCommandEventArgs.cs
- StylusPoint.cs
- RecipientInfo.cs
- FloatSumAggregationOperator.cs
- IOException.cs
- TypeDependencyAttribute.cs
- WebPartConnectionCollection.cs
- TcpClientSocketManager.cs
- TextEffectCollection.cs
- ProtocolsConfiguration.cs
- InsufficientMemoryException.cs
- TextTreeText.cs
- DataTemplate.cs
- HtmlInputReset.cs
- CatalogZoneAutoFormat.cs
- HandleCollector.cs
- PreviewPageInfo.cs
- SuppressMessageAttribute.cs
- PropertyGeneratedEventArgs.cs
- UpdateTracker.cs
- ResourcePermissionBaseEntry.cs
- NumericUpDown.cs
- AdornerHitTestResult.cs
- ObjectNavigationPropertyMapping.cs
- JavaScriptSerializer.cs
- ObjectQueryState.cs
- EmulateRecognizeCompletedEventArgs.cs
- DesigntimeLicenseContextSerializer.cs
- TextPointer.cs
- SpellerHighlightLayer.cs
- TextEditorParagraphs.cs
- ISCIIEncoding.cs
- Transform3DGroup.cs
- CharacterShapingProperties.cs
- WeakReference.cs
- DocumentOrderQuery.cs
- QualificationDataItem.cs
- XPathNavigatorKeyComparer.cs
- PersonalizationStateInfoCollection.cs
- Menu.cs
- ResourcePermissionBaseEntry.cs
- WorkflowInstanceAbortedRecord.cs
- SessionState.cs
- BindingManagerDataErrorEventArgs.cs
- TypeHelpers.cs
- log.cs
- VirtualPathUtility.cs
- AllowedAudienceUriElement.cs
- DesignTimeVisibleAttribute.cs
- ServiceThrottle.cs
- DetailsViewRow.cs
- ListenerElementsCollection.cs
- Color.cs
- InvalidAsynchronousStateException.cs
- DesignerInterfaces.cs
- ModelItemDictionary.cs
- RawAppCommandInputReport.cs
- ISAPIRuntime.cs
- TimeSpan.cs
- TextReturnReader.cs
- StatusBarAutomationPeer.cs
- BufferBuilder.cs
- RangeExpression.cs
- HtmlAnchor.cs
- DesignerExtenders.cs
- BoundField.cs
- ExpressionLexer.cs
- HttpCachePolicy.cs
- SecurityElement.cs
- WindowsScrollBar.cs
- BindingCollection.cs
- RestHandler.cs
- FileDialog_Vista_Interop.cs
- ThrowHelper.cs
- StreamReader.cs
- RequestNavigateEventArgs.cs
- MonitorWrapper.cs
- SmiTypedGetterSetter.cs
- FieldInfo.cs
- ContextBase.cs