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;
///
///
///
/// 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.
///
///
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.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Configuration {
using System.Configuration.Internal;
using System.IO;
using System.Xml;
using System.Runtime.Versioning;
///
///
///
/// 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.
///
///
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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- StylusPointProperties.cs
- LifetimeServices.cs
- SHA384.cs
- DataGridViewRowPrePaintEventArgs.cs
- SHA1CryptoServiceProvider.cs
- DocumentReference.cs
- XmlToDatasetMap.cs
- AttributedMetaModel.cs
- FontNamesConverter.cs
- RequestQueue.cs
- ServiceMemoryGates.cs
- ClientScriptManager.cs
- DrawingVisualDrawingContext.cs
- Window.cs
- MobileUserControlDesigner.cs
- FastPropertyAccessor.cs
- ToolboxItemCollection.cs
- IdleTimeoutMonitor.cs
- WpfXamlType.cs
- ItemContainerGenerator.cs
- RequestResizeEvent.cs
- RSAOAEPKeyExchangeDeformatter.cs
- GroupByQueryOperator.cs
- XamlTemplateSerializer.cs
- PasswordTextNavigator.cs
- EntityFunctions.cs
- X500Name.cs
- RectAnimation.cs
- RowsCopiedEventArgs.cs
- UInt32Converter.cs
- SqlDuplicator.cs
- WebPartCancelEventArgs.cs
- Point3D.cs
- LocatorBase.cs
- RotateTransform3D.cs
- UnhandledExceptionEventArgs.cs
- ChangePasswordDesigner.cs
- VirtualizingPanel.cs
- ComponentEditorPage.cs
- ComAdminWrapper.cs
- XmlReflectionMember.cs
- DataError.cs
- ListenerTraceUtility.cs
- MetadataImporter.cs
- PhoneCall.cs
- KerberosTokenFactoryCredential.cs
- KeyMatchBuilder.cs
- DataGrid.cs
- PageCache.cs
- NodeCounter.cs
- SizeF.cs
- CroppedBitmap.cs
- TrimSurroundingWhitespaceAttribute.cs
- SQLBinary.cs
- SqlMethodAttribute.cs
- XmlWrappingWriter.cs
- ThicknessAnimation.cs
- SqlOuterApplyReducer.cs
- AssemblyAttributes.cs
- NavigationHelper.cs
- OdbcCommand.cs
- XmlCustomFormatter.cs
- CreateUserErrorEventArgs.cs
- OrderPreservingPipeliningMergeHelper.cs
- MetadataPropertyAttribute.cs
- EnvelopedSignatureTransform.cs
- Int32AnimationBase.cs
- XmlText.cs
- SqlRemoveConstantOrderBy.cs
- CollectionDataContract.cs
- EventBuilder.cs
- SignedPkcs7.cs
- TimeSpanMinutesConverter.cs
- PassportAuthenticationEventArgs.cs
- SqlDataSourceRefreshSchemaForm.cs
- DnsElement.cs
- PixelFormats.cs
- RemotingException.cs
- ObjectResult.cs
- MimeObjectFactory.cs
- SqlConnectionPoolGroupProviderInfo.cs
- GenericRootAutomationPeer.cs
- ImpersonationContext.cs
- BackStopAuthenticationModule.cs
- MessageBox.cs
- AutomationPatternInfo.cs
- PointCollection.cs
- SingleConverter.cs
- And.cs
- TextBoxRenderer.cs
- ListViewUpdatedEventArgs.cs
- UpdatePanelControlTrigger.cs
- TrustSection.cs
- ClientSideQueueItem.cs
- Aggregates.cs
- ClientBuildManagerCallback.cs
- Cloud.cs
- CodeTypeParameter.cs
- UniqueIdentifierService.cs
- SystemEvents.cs