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
- FixedHyperLink.cs
- LocatorManager.cs
- AbstractExpressions.cs
- XmlWrappingReader.cs
- DataColumnPropertyDescriptor.cs
- Component.cs
- LedgerEntryCollection.cs
- DbConnectionStringBuilder.cs
- DrawingBrush.cs
- SimpleExpression.cs
- ISCIIEncoding.cs
- XmlSchemaImport.cs
- PeerNameResolver.cs
- ManagedWndProcTracker.cs
- Menu.cs
- WebPartUtil.cs
- AnnotationService.cs
- _Connection.cs
- PathFigureCollection.cs
- Knowncolors.cs
- ToolConsole.cs
- ScriptControlManager.cs
- odbcmetadatafactory.cs
- TextRangeAdaptor.cs
- SessionStateModule.cs
- RedistVersionInfo.cs
- DocumentPageViewAutomationPeer.cs
- HttpCookie.cs
- IntranetCredentialPolicy.cs
- EntityDataSourceState.cs
- CodeSubDirectoriesCollection.cs
- SingleResultAttribute.cs
- ButtonBase.cs
- GeometryGroup.cs
- DependentList.cs
- ClrProviderManifest.cs
- LicenseException.cs
- SecuritySessionFilter.cs
- DataServiceConfiguration.cs
- SharedStatics.cs
- ScriptHandlerFactory.cs
- EdmMember.cs
- StylusTip.cs
- EncoderExceptionFallback.cs
- ListBoxItem.cs
- PeerOutputChannel.cs
- RtfNavigator.cs
- PngBitmapEncoder.cs
- Panel.cs
- ButtonBase.cs
- ConfigXmlAttribute.cs
- InvokePatternIdentifiers.cs
- BroadcastEventHelper.cs
- TextEncodedRawTextWriter.cs
- Attributes.cs
- TextMarkerSource.cs
- TemplateControlCodeDomTreeGenerator.cs
- TextPatternIdentifiers.cs
- InputLanguageProfileNotifySink.cs
- InitializerFacet.cs
- SMSvcHost.cs
- DependencyPropertyHelper.cs
- MenuStrip.cs
- PingReply.cs
- StylusButton.cs
- TitleStyle.cs
- DataGridViewTopLeftHeaderCell.cs
- XmlQueryContext.cs
- BoolLiteral.cs
- OleDbFactory.cs
- ComboBox.cs
- UserValidatedEventArgs.cs
- Invariant.cs
- URIFormatException.cs
- DetailsViewCommandEventArgs.cs
- TypeConverter.cs
- RemotingException.cs
- SimpleColumnProvider.cs
- NamespaceImport.cs
- CategoryGridEntry.cs
- WebPartEventArgs.cs
- ProxyManager.cs
- ServiceDesigner.xaml.cs
- QueryableDataSourceHelper.cs
- WebPartCollection.cs
- SettingsPropertyWrongTypeException.cs
- BackgroundFormatInfo.cs
- Variant.cs
- X509Certificate2.cs
- X509ChainElement.cs
- SafeViewOfFileHandle.cs
- PolicyImporterElement.cs
- WeakReferenceList.cs
- SmiEventSink.cs
- DiffuseMaterial.cs
- XmlTextReader.cs
- ColumnClickEvent.cs
- ColumnPropertiesGroup.cs
- HttpException.cs
- EventOpcode.cs