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
- UserNamePasswordClientCredential.cs
- UIPropertyMetadata.cs
- CollectionType.cs
- IntAverageAggregationOperator.cs
- PeerApplicationLaunchInfo.cs
- DefaultBindingPropertyAttribute.cs
- EntityDataSourceState.cs
- AdapterUtil.cs
- ModuleBuilder.cs
- UseLicense.cs
- BinaryUtilClasses.cs
- DesignerSerializerAttribute.cs
- ApplicationFileParser.cs
- ParameterSubsegment.cs
- RegexNode.cs
- ColorConverter.cs
- ReflectPropertyDescriptor.cs
- ToolStripItemRenderEventArgs.cs
- WindowsIdentity.cs
- GetWinFXPath.cs
- RefType.cs
- EntityCollection.cs
- TargetInvocationException.cs
- ProjectionCamera.cs
- TextBoxBase.cs
- DocumentPageView.cs
- RSAOAEPKeyExchangeFormatter.cs
- WSSecureConversationDec2005.cs
- Object.cs
- XamlClipboardData.cs
- XPathDocumentNavigator.cs
- ActivityMarkupSerializer.cs
- PaintEvent.cs
- ArrayConverter.cs
- EventWaitHandle.cs
- HttpDebugHandler.cs
- PagePropertiesChangingEventArgs.cs
- AsymmetricAlgorithm.cs
- TextBoxAutoCompleteSourceConverter.cs
- RSAPKCS1SignatureFormatter.cs
- ObjRef.cs
- XmlSchemaType.cs
- NativeWindow.cs
- DataProtection.cs
- LayoutEngine.cs
- ScopelessEnumAttribute.cs
- ToolStripLabel.cs
- StreamResourceInfo.cs
- UrlMappingsSection.cs
- HyperLinkDataBindingHandler.cs
- DataGridViewLinkCell.cs
- CompiledQuery.cs
- MissingSatelliteAssemblyException.cs
- XmlIlTypeHelper.cs
- OleDbStruct.cs
- Array.cs
- DataGridParentRows.cs
- DataGridTablesFactory.cs
- ScriptBehaviorDescriptor.cs
- DynamicArgumentDesigner.xaml.cs
- ProfileGroupSettings.cs
- TypeListConverter.cs
- ResourceReader.cs
- StorageComplexTypeMapping.cs
- Renderer.cs
- SqlGatherConsumedAliases.cs
- ToolStripItemImageRenderEventArgs.cs
- TextDocumentView.cs
- DataReceivedEventArgs.cs
- AuthenticationSection.cs
- OneOfConst.cs
- HyperLinkField.cs
- AVElementHelper.cs
- UpdateEventArgs.cs
- SqlNotificationRequest.cs
- Processor.cs
- NGCSerializationManager.cs
- HtmlInputRadioButton.cs
- ValueTypeFixupInfo.cs
- XmlElementAttributes.cs
- ApplicationProxyInternal.cs
- ScriptResourceHandler.cs
- handlecollector.cs
- ProfileSettings.cs
- TextFormatter.cs
- SafePointer.cs
- Light.cs
- DataServiceRequestArgs.cs
- FixedPageProcessor.cs
- ListViewItem.cs
- BinaryReader.cs
- InputScopeAttribute.cs
- PageContent.cs
- StringTraceRecord.cs
- RequestResizeEvent.cs
- ToolStripMenuItem.cs
- RubberbandSelector.cs
- UpdatePanelTriggerCollection.cs
- KeyGesture.cs
- MimeMapping.cs