Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- Utils.cs
- WorkflowEnvironment.cs
- TextContainerHelper.cs
- DataGridViewCheckBoxColumn.cs
- BulletChrome.cs
- TransformDescriptor.cs
- DirtyTextRange.cs
- ScopelessEnumAttribute.cs
- Util.cs
- ImageAutomationPeer.cs
- WebBaseEventKeyComparer.cs
- ComPlusSynchronizationContext.cs
- BitmapEffectState.cs
- COM2ExtendedBrowsingHandler.cs
- MethodImplAttribute.cs
- DataListItemEventArgs.cs
- XDRSchema.cs
- DataFormats.cs
- ResXResourceWriter.cs
- ActivitySurrogate.cs
- Attribute.cs
- XmlSchemaExporter.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- Package.cs
- MonitoringDescriptionAttribute.cs
- GcHandle.cs
- SerializationAttributes.cs
- GuidConverter.cs
- RightsManagementInformation.cs
- CryptographicAttribute.cs
- columnmapkeybuilder.cs
- FunctionCommandText.cs
- BuildProviderUtils.cs
- DiscoveryServiceExtension.cs
- RequestBringIntoViewEventArgs.cs
- SystemColors.cs
- SrgsGrammar.cs
- ReaderWriterLockSlim.cs
- Control.cs
- EnumValAlphaComparer.cs
- UseAttributeSetsAction.cs
- PassportPrincipal.cs
- SelectionWordBreaker.cs
- StreamWithDictionary.cs
- Int16Converter.cs
- SamlAdvice.cs
- IsolatedStorageException.cs
- PackagePart.cs
- WebResourceAttribute.cs
- TypedTableBase.cs
- ToolStripHighContrastRenderer.cs
- InputScopeConverter.cs
- IListConverters.cs
- SqlDeflator.cs
- DataGridViewRowPrePaintEventArgs.cs
- WizardSideBarListControlItemEventArgs.cs
- BaseCollection.cs
- DynamicHyperLink.cs
- XPathDocumentNavigator.cs
- ObjectDataSourceDisposingEventArgs.cs
- SQLBinary.cs
- HttpWebRequest.cs
- LocatorBase.cs
- Crc32Helper.cs
- XmlAnyElementAttributes.cs
- AuthorizationSection.cs
- SchemaElement.cs
- RuntimeArgumentHandle.cs
- PeoplePickerWrapper.cs
- XsltContext.cs
- XmlReturnWriter.cs
- IgnoreDeviceFilterElementCollection.cs
- XmlWriter.cs
- ParameterToken.cs
- SudsWriter.cs
- BitmapVisualManager.cs
- FieldAccessException.cs
- HtmlImage.cs
- Brushes.cs
- DPAPIProtectedConfigurationProvider.cs
- ListItemCollection.cs
- ResourceDescriptionAttribute.cs
- ComplexPropertyEntry.cs
- TreeWalker.cs
- HandlerBase.cs
- RelOps.cs
- DesignerDataStoredProcedure.cs
- XmlBinaryReaderSession.cs
- ControlCollection.cs
- CodeDomConfigurationHandler.cs
- ActivityBindForm.Designer.cs
- SinglePageViewer.cs
- SetState.cs
- WindowsIdentity.cs
- VectorAnimationBase.cs
- WebPartPersonalization.cs
- Model3D.cs
- PageEventArgs.cs
- QuaternionValueSerializer.cs
- WebPartZoneDesigner.cs