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 / NameValueSectionHandler.cs / 1 / NameValueSectionHandler.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Configuration {
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Globalization;
///
/// Simple dictionary config factory
///
public class NameValueSectionHandler : IConfigurationSectionHandler {
const string defaultKeyAttribute = "key";
const string defaultValueAttribute = "value";
///
/// [To be supplied.]
///
public object Create(object parent, object context, XmlNode section) {
return CreateStatic(parent, section, KeyAttributeName, ValueAttributeName);
}
internal static object CreateStatic(object parent, XmlNode section) {
return CreateStatic(parent, section, defaultKeyAttribute, defaultValueAttribute);
}
internal static object CreateStatic(object parent, XmlNode section, string keyAttriuteName, string valueAttributeName) {
ReadOnlyNameValueCollection result;
// start result off as a shallow clone of the parent
if (parent == null)
result = new ReadOnlyNameValueCollection(StringComparer.OrdinalIgnoreCase);
else {
ReadOnlyNameValueCollection parentCollection = (ReadOnlyNameValueCollection)parent;
result = new ReadOnlyNameValueCollection(parentCollection);
}
// process XML
HandlerBase.CheckForUnrecognizedAttributes(section);
foreach (XmlNode child in section.ChildNodes) {
// skip whitespace and comments
if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
continue;
// handle , , tags
if (child.Name == "add") {
String key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName);
String value = HandlerBase.RemoveRequiredAttribute(child, valueAttributeName, true/*allowEmptyString*/);
HandlerBase.CheckForUnrecognizedAttributes(child);
result[key] = value;
}
else if (child.Name == "remove") {
String key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName);
HandlerBase.CheckForUnrecognizedAttributes(child);
result.Remove(key);
}
else if (child.Name.Equals("clear")) {
HandlerBase.CheckForUnrecognizedAttributes(child);
result.Clear();
}
else {
HandlerBase.ThrowUnrecognizedElement(child);
}
}
result.SetReadOnly();
return result;
}
///
/// [To be supplied.]
///
protected virtual string KeyAttributeName {
get { return defaultKeyAttribute;}
}
///
/// [To be supplied.]
///
protected virtual string ValueAttributeName {
get { return defaultValueAttribute;}
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.Configuration {
using System.Collections;
using System.Collections.Specialized;
using System.Xml;
using System.Globalization;
///
/// Simple dictionary config factory
///
public class NameValueSectionHandler : IConfigurationSectionHandler {
const string defaultKeyAttribute = "key";
const string defaultValueAttribute = "value";
///
/// [To be supplied.]
///
public object Create(object parent, object context, XmlNode section) {
return CreateStatic(parent, section, KeyAttributeName, ValueAttributeName);
}
internal static object CreateStatic(object parent, XmlNode section) {
return CreateStatic(parent, section, defaultKeyAttribute, defaultValueAttribute);
}
internal static object CreateStatic(object parent, XmlNode section, string keyAttriuteName, string valueAttributeName) {
ReadOnlyNameValueCollection result;
// start result off as a shallow clone of the parent
if (parent == null)
result = new ReadOnlyNameValueCollection(StringComparer.OrdinalIgnoreCase);
else {
ReadOnlyNameValueCollection parentCollection = (ReadOnlyNameValueCollection)parent;
result = new ReadOnlyNameValueCollection(parentCollection);
}
// process XML
HandlerBase.CheckForUnrecognizedAttributes(section);
foreach (XmlNode child in section.ChildNodes) {
// skip whitespace and comments
if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
continue;
// handle , , tags
if (child.Name == "add") {
String key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName);
String value = HandlerBase.RemoveRequiredAttribute(child, valueAttributeName, true/*allowEmptyString*/);
HandlerBase.CheckForUnrecognizedAttributes(child);
result[key] = value;
}
else if (child.Name == "remove") {
String key = HandlerBase.RemoveRequiredAttribute(child, keyAttriuteName);
HandlerBase.CheckForUnrecognizedAttributes(child);
result.Remove(key);
}
else if (child.Name.Equals("clear")) {
HandlerBase.CheckForUnrecognizedAttributes(child);
result.Clear();
}
else {
HandlerBase.ThrowUnrecognizedElement(child);
}
}
result.SetReadOnly();
return result;
}
///
/// [To be supplied.]
///
protected virtual string KeyAttributeName {
get { return defaultKeyAttribute;}
}
///
/// [To be supplied.]
///
protected virtual string ValueAttributeName {
get { return defaultValueAttribute;}
}
}
}
// 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
- OutgoingWebRequestContext.cs
- ElementNotEnabledException.cs
- ChannelServices.cs
- SingletonChannelAcceptor.cs
- BindingMAnagerBase.cs
- RecognizerInfo.cs
- ListItemConverter.cs
- OdbcConnectionOpen.cs
- QueueProcessor.cs
- ItemCheckedEvent.cs
- FilterException.cs
- ShaderRenderModeValidation.cs
- ErrorHandler.cs
- ServiceDocument.cs
- SqlUnionizer.cs
- TextStore.cs
- ModelUtilities.cs
- ObjectNavigationPropertyMapping.cs
- AttachmentService.cs
- EntityChangedParams.cs
- SelectionEditor.cs
- PropVariant.cs
- EvidenceBase.cs
- HasRunnableWorkflowEvent.cs
- MailBnfHelper.cs
- TextEditorTables.cs
- PublishLicense.cs
- ResourceIDHelper.cs
- Point3DAnimation.cs
- ReachPageContentSerializer.cs
- ToolStripSeparator.cs
- SoapCommonClasses.cs
- EditBehavior.cs
- GridLengthConverter.cs
- Polyline.cs
- UnsafeNativeMethods.cs
- Duration.cs
- ColumnHeaderConverter.cs
- RichTextBox.cs
- CategoryGridEntry.cs
- WinEventWrap.cs
- ByteKeyFrameCollection.cs
- BooleanAnimationUsingKeyFrames.cs
- DataControlFieldCollection.cs
- SecUtil.cs
- UnconditionalPolicy.cs
- ConvertTextFrag.cs
- DataContractSerializer.cs
- Base64Stream.cs
- TimelineGroup.cs
- ObjectDataSourceChooseTypePanel.cs
- ColorConvertedBitmapExtension.cs
- Membership.cs
- ModifiableIteratorCollection.cs
- Menu.cs
- ErrorLog.cs
- FormViewUpdatedEventArgs.cs
- ReadOnlyTernaryTree.cs
- _UriTypeConverter.cs
- FrameAutomationPeer.cs
- LogicalExpr.cs
- DictionarySectionHandler.cs
- Internal.cs
- GridItem.cs
- WmlImageAdapter.cs
- ClientCultureInfo.cs
- EntityDataSourceState.cs
- WebPartDescriptionCollection.cs
- EventlogProvider.cs
- AlternateViewCollection.cs
- BinarySerializer.cs
- AttributeQuery.cs
- ColorTransform.cs
- SemanticBasicElement.cs
- DockAndAnchorLayout.cs
- CurrentChangingEventArgs.cs
- HandleDictionary.cs
- AdapterDictionary.cs
- UndoManager.cs
- WebHttpEndpointElement.cs
- QueuePathDialog.cs
- StringFreezingAttribute.cs
- ProcessThreadCollection.cs
- WebConfigurationHost.cs
- OracleDataAdapter.cs
- SecurityContext.cs
- ToolStripButton.cs
- Converter.cs
- NGCUIElementCollectionSerializerAsync.cs
- InternalRelationshipCollection.cs
- XmlDocumentType.cs
- validation.cs
- SqlException.cs
- GraphicsState.cs
- ImageClickEventArgs.cs
- RemotingConfigParser.cs
- TrackingDataItem.cs
- HwndMouseInputProvider.cs
- BatchParser.cs
- CodeTypeMember.cs