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
- InheritanceContextChangedEventManager.cs
- XPathAncestorIterator.cs
- AssociationTypeEmitter.cs
- MenuItemStyle.cs
- HierarchicalDataTemplate.cs
- WindowsTokenRoleProvider.cs
- ToolBarButtonClickEvent.cs
- BindValidationContext.cs
- DataGridViewComboBoxEditingControl.cs
- VariableAction.cs
- Int16Converter.cs
- TextRunCacheImp.cs
- PeerToPeerException.cs
- SRGSCompiler.cs
- SafeProcessHandle.cs
- FormClosingEvent.cs
- ELinqQueryState.cs
- WebPart.cs
- UnsafeCollabNativeMethods.cs
- WsatServiceCertificate.cs
- DocumentViewerBase.cs
- SeparatorAutomationPeer.cs
- AuthenticationService.cs
- DictionaryContent.cs
- SingleBodyParameterMessageFormatter.cs
- AccessedThroughPropertyAttribute.cs
- Animatable.cs
- Evidence.cs
- UnsafeNativeMethods.cs
- GridView.cs
- X500Name.cs
- OciEnlistContext.cs
- TimeoutException.cs
- CancellationTokenSource.cs
- ModuleBuilderData.cs
- EntityContainer.cs
- OracleString.cs
- TextModifier.cs
- HttpWebResponse.cs
- HtmlTable.cs
- UmAlQuraCalendar.cs
- NonSerializedAttribute.cs
- WebPartZoneCollection.cs
- IntranetCredentialPolicy.cs
- ReturnType.cs
- StrongNameSignatureInformation.cs
- ItemCollectionEditor.cs
- CaseStatement.cs
- CounterSetInstanceCounterDataSet.cs
- SimpleTypeResolver.cs
- ResXBuildProvider.cs
- LogLogRecordHeader.cs
- QuaternionRotation3D.cs
- ShaderRenderModeValidation.cs
- DbDataSourceEnumerator.cs
- DataServiceEntityAttribute.cs
- LineSegment.cs
- DataGridClipboardHelper.cs
- SelectionBorderGlyph.cs
- MultipartIdentifier.cs
- OleAutBinder.cs
- ProxyWebPartManager.cs
- RectAnimationUsingKeyFrames.cs
- ThaiBuddhistCalendar.cs
- MultipartContentParser.cs
- AuthorizationSection.cs
- DataRelationCollection.cs
- StringInfo.cs
- __FastResourceComparer.cs
- XhtmlBasicSelectionListAdapter.cs
- Int16AnimationUsingKeyFrames.cs
- PageThemeParser.cs
- XamlTypeMapperSchemaContext.cs
- ElementFactory.cs
- RayMeshGeometry3DHitTestResult.cs
- NamespaceInfo.cs
- Semaphore.cs
- BamlRecordHelper.cs
- AsyncResult.cs
- PeerInvitationResponse.cs
- CompiledIdentityConstraint.cs
- PropertyBuilder.cs
- ListViewGroup.cs
- SizeConverter.cs
- xmlglyphRunInfo.cs
- AxImporter.cs
- DesignerActionUIService.cs
- GenericTypeParameterBuilder.cs
- XPathChildIterator.cs
- ErrorStyle.cs
- FlowDocumentScrollViewer.cs
- _CookieModule.cs
- MemoryFailPoint.cs
- SafeJobHandle.cs
- ImageSourceValueSerializer.cs
- MaskedTextProvider.cs
- EntityTypeEmitter.cs
- ServicesUtilities.cs
- sqlpipe.cs
- PartBasedPackageProperties.cs