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
- FieldBuilder.cs
- GridView.cs
- CodeTypeDeclarationCollection.cs
- ProcessModelSection.cs
- FileDialog_Vista_Interop.cs
- InternalsVisibleToAttribute.cs
- MenuAdapter.cs
- WebPartUserCapability.cs
- XmlFormatExtensionPrefixAttribute.cs
- WeakReferenceEnumerator.cs
- SqlPersonalizationProvider.cs
- TreeNode.cs
- LinkAreaEditor.cs
- EntityWithChangeTrackerStrategy.cs
- TextComposition.cs
- PointConverter.cs
- CompiledQuery.cs
- InputProcessorProfiles.cs
- UIEndRequest.cs
- MouseButtonEventArgs.cs
- FieldAccessException.cs
- CustomExpression.cs
- DataRowExtensions.cs
- SapiRecoInterop.cs
- KoreanLunisolarCalendar.cs
- KeyValueConfigurationCollection.cs
- DropShadowBitmapEffect.cs
- InertiaExpansionBehavior.cs
- OleDbConnectionInternal.cs
- SecurityDescriptor.cs
- WindowsRebar.cs
- OleCmdHelper.cs
- HttpFileCollection.cs
- WebConfigurationHost.cs
- DependencyObject.cs
- DefaultShape.cs
- GroupBox.cs
- UICuesEvent.cs
- NetSectionGroup.cs
- ScriptingJsonSerializationSection.cs
- CodeDirectionExpression.cs
- TypeNameHelper.cs
- PathStreamGeometryContext.cs
- MetadataArtifactLoaderCompositeResource.cs
- NamedElement.cs
- MD5HashHelper.cs
- CompositeControl.cs
- TiffBitmapEncoder.cs
- HScrollProperties.cs
- ProfilePropertyNameValidator.cs
- FigureParagraph.cs
- SafeSystemMetrics.cs
- WorkflowFileItem.cs
- UnitySerializationHolder.cs
- SQlBooleanStorage.cs
- EditBehavior.cs
- MarkupObject.cs
- ThrowHelper.cs
- ArrangedElement.cs
- LinqDataSourceEditData.cs
- SerializerProvider.cs
- Image.cs
- BinaryMethodMessage.cs
- DateBoldEvent.cs
- TreeNodeStyle.cs
- CharacterMetricsDictionary.cs
- RoleManagerModule.cs
- ChangeProcessor.cs
- RegexWriter.cs
- IconConverter.cs
- MemberProjectedSlot.cs
- ImplicitInputBrush.cs
- LineMetrics.cs
- FixedSOMContainer.cs
- InputProcessorProfilesLoader.cs
- CurrentChangingEventArgs.cs
- _StreamFramer.cs
- TCPListener.cs
- TypeUtil.cs
- ClientBuildManagerCallback.cs
- BatchWriter.cs
- TextRunCache.cs
- XsltOutput.cs
- ToolStripCodeDomSerializer.cs
- SkewTransform.cs
- EmptyReadOnlyDictionaryInternal.cs
- PageCodeDomTreeGenerator.cs
- FontResourceCache.cs
- PhysicalOps.cs
- PkcsMisc.cs
- LogSwitch.cs
- Authorization.cs
- PopupControlService.cs
- ClassImporter.cs
- QueueTransferProtocol.cs
- SyndicationContent.cs
- ComboBoxItem.cs
- TableItemStyle.cs
- TypeGeneratedEventArgs.cs
- UpdatePanel.cs