Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- counter.cs
- control.ime.cs
- TextTreeDeleteContentUndoUnit.cs
- WebPartRestoreVerb.cs
- WebPartEditVerb.cs
- ApplicationTrust.cs
- AdapterSwitches.cs
- ListBase.cs
- listitem.cs
- DataGridColumnCollection.cs
- Pens.cs
- Size.cs
- BitSet.cs
- RectAnimationBase.cs
- Hashtable.cs
- TextOnlyOutput.cs
- BadImageFormatException.cs
- XmlReflectionImporter.cs
- DropShadowBitmapEffect.cs
- Point3DValueSerializer.cs
- PartBasedPackageProperties.cs
- VerbConverter.cs
- CFGGrammar.cs
- Choices.cs
- COM2ColorConverter.cs
- InputLangChangeRequestEvent.cs
- GridPattern.cs
- ServerType.cs
- XmlCDATASection.cs
- TextEndOfParagraph.cs
- ActiveDocumentEvent.cs
- IDQuery.cs
- DesignOnlyAttribute.cs
- CollectionEditVerbManager.cs
- Opcode.cs
- CodeEventReferenceExpression.cs
- PermissionSetEnumerator.cs
- Geometry.cs
- StrongNamePublicKeyBlob.cs
- SrgsRule.cs
- UnsignedPublishLicense.cs
- WorkflowInstanceExtensionManager.cs
- PipeStream.cs
- SiteMapDataSourceDesigner.cs
- EntityContainer.cs
- ValueTable.cs
- MobileListItem.cs
- CloudCollection.cs
- KeySpline.cs
- RangeValueProviderWrapper.cs
- FontWeights.cs
- BitmapEffect.cs
- CodeLinePragma.cs
- RequestQueryParser.cs
- TracingConnectionListener.cs
- BindingWorker.cs
- safelink.cs
- ConnectorSelectionGlyph.cs
- WpfKnownMemberInvoker.cs
- TextParagraph.cs
- TextBox.cs
- BitmapEffectInput.cs
- ColorAnimationBase.cs
- OptimisticConcurrencyException.cs
- Logging.cs
- NoResizeHandleGlyph.cs
- FormatterConverter.cs
- StrokeNodeOperations.cs
- CompilerTypeWithParams.cs
- FlowDocumentScrollViewerAutomationPeer.cs
- ConfigXmlComment.cs
- ListViewTableCell.cs
- RegexInterpreter.cs
- FilteredAttributeCollection.cs
- TransportDefaults.cs
- basevalidator.cs
- Bezier.cs
- DataStorage.cs
- LineGeometry.cs
- Privilege.cs
- EtwTrace.cs
- DataFieldConverter.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- SqlServer2KCompatibilityCheck.cs
- UpdatePanel.cs
- GlyphShapingProperties.cs
- MetadataItemEmitter.cs
- ApplicationTrust.cs
- DesignerCategoryAttribute.cs
- WindowsTooltip.cs
- SpellCheck.cs
- TextTreeUndoUnit.cs
- ValidatorCompatibilityHelper.cs
- FaultPropagationQuery.cs
- HtmlTableCellCollection.cs
- AssemblyNameProxy.cs
- MorphHelper.cs
- ISO2022Encoding.cs
- ComponentConverter.cs
- DataGridViewButtonColumn.cs