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;
///
///
///
/// 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
- URL.cs
- ShimAsPublicXamlType.cs
- ContractComponent.cs
- HttpServerVarsCollection.cs
- SafeArchiveContext.cs
- ExpressionBinding.cs
- DbConnectionStringCommon.cs
- SafeRightsManagementSessionHandle.cs
- IssuedTokenParametersEndpointAddressElement.cs
- DispatcherObject.cs
- HttpProcessUtility.cs
- ElementFactory.cs
- KnownColorTable.cs
- ContractCodeDomInfo.cs
- HuffModule.cs
- XmlILAnnotation.cs
- SpanIndex.cs
- BinaryFormatterSinks.cs
- TimeSpan.cs
- Typeface.cs
- HandledMouseEvent.cs
- TreeNode.cs
- CommunicationObjectFaultedException.cs
- AnnotationHelper.cs
- OdbcCommand.cs
- ObjectDataSourceFilteringEventArgs.cs
- OdbcTransaction.cs
- PresentationTraceSources.cs
- PropertyConverter.cs
- CustomBindingElementCollection.cs
- Point3DKeyFrameCollection.cs
- SingleObjectCollection.cs
- HtmlFormWrapper.cs
- FilteredXmlReader.cs
- CompatibleIComparer.cs
- DataBinder.cs
- MimeAnyImporter.cs
- UrlPropertyAttribute.cs
- Clause.cs
- DiscoveryInnerClientAdhocCD1.cs
- ISAPIRuntime.cs
- OSEnvironmentHelper.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- MenuItem.cs
- AnnotationStore.cs
- EmbeddedMailObjectsCollection.cs
- ByteStack.cs
- HttpModuleCollection.cs
- ContextMenu.cs
- DataIdProcessor.cs
- FixedTextSelectionProcessor.cs
- XMLUtil.cs
- SpotLight.cs
- SchemaNamespaceManager.cs
- CacheChildrenQuery.cs
- FixedSOMContainer.cs
- WindowsListBox.cs
- ThreadPool.cs
- OdbcHandle.cs
- RenderData.cs
- DataSourceCacheDurationConverter.cs
- ProfileSettingsCollection.cs
- ArgIterator.cs
- XmlJsonReader.cs
- ByteStreamGeometryContext.cs
- LabelInfo.cs
- QueryExpression.cs
- ButtonBase.cs
- ImageMap.cs
- CompositeTypefaceMetrics.cs
- MultipleViewPattern.cs
- AffineTransform3D.cs
- WindowsFormsSectionHandler.cs
- DrawingContextWalker.cs
- SemanticBasicElement.cs
- RedirectionProxy.cs
- CheckedPointers.cs
- Opcode.cs
- WebSysDefaultValueAttribute.cs
- ProjectionCamera.cs
- ServiceTimeoutsElement.cs
- CharEnumerator.cs
- NegotiateStream.cs
- _OSSOCK.cs
- StylusPointProperty.cs
- NavigationWindow.cs
- CngKeyCreationParameters.cs
- ObjectReferenceStack.cs
- FontNamesConverter.cs
- SetState.cs
- __ComObject.cs
- InputDevice.cs
- ServiceDescriptionData.cs
- DataKeyArray.cs
- DataFormats.cs
- GeneralTransform.cs
- IndependentAnimationStorage.cs
- EnvelopedSignatureTransform.cs
- EntityStoreSchemaFilterEntry.cs
- StateChangeEvent.cs