Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / 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
- ServerValidateEventArgs.cs
- HttpHandlerActionCollection.cs
- Module.cs
- ItemList.cs
- Container.cs
- GlyphInfoList.cs
- EntityKey.cs
- StateItem.cs
- PropertyToken.cs
- ImageBrush.cs
- QuaternionValueSerializer.cs
- DrawingContext.cs
- DataServiceSaveChangesEventArgs.cs
- future.cs
- DropTarget.cs
- MimeParameter.cs
- PropertyCollection.cs
- Transform.cs
- DefaultMemberAttribute.cs
- WinInet.cs
- Model3DGroup.cs
- PermissionSetTriple.cs
- ReliableSessionBindingElementImporter.cs
- GroupedContextMenuStrip.cs
- LinqDataSourceContextEventArgs.cs
- _ContextAwareResult.cs
- ConditionValidator.cs
- FixedTextPointer.cs
- _ChunkParse.cs
- SQLBinary.cs
- MLangCodePageEncoding.cs
- PageAsyncTask.cs
- NumericUpDownAccelerationCollection.cs
- Point.cs
- RequestChannelBinder.cs
- JournalEntry.cs
- OdbcParameter.cs
- BitmapEffectInput.cs
- XmlSerializerOperationBehavior.cs
- ColumnResult.cs
- SocketPermission.cs
- Latin1Encoding.cs
- VisualTreeUtils.cs
- FormViewDeleteEventArgs.cs
- DbConnectionFactory.cs
- Wrapper.cs
- DomainUpDown.cs
- Quack.cs
- SizeChangedEventArgs.cs
- RadioButtonList.cs
- ListViewContainer.cs
- KeyboardInputProviderAcquireFocusEventArgs.cs
- View.cs
- HttpResponseInternalBase.cs
- AttributeParameterInfo.cs
- ExtenderProvidedPropertyAttribute.cs
- XmlNamedNodeMap.cs
- HttpRuntime.cs
- UnmanagedMemoryStreamWrapper.cs
- PropertyOverridesTypeEditor.cs
- WebCodeGenerator.cs
- SingleStorage.cs
- DataAccessor.cs
- SchemaInfo.cs
- ClientScriptItemCollection.cs
- CompletionBookmark.cs
- Util.cs
- RedistVersionInfo.cs
- InfoCardKeyedHashAlgorithm.cs
- CodeDomExtensionMethods.cs
- WebCategoryAttribute.cs
- XsdDateTime.cs
- CreateUserErrorEventArgs.cs
- GradientBrush.cs
- Range.cs
- MessageAction.cs
- SQLRoleProvider.cs
- NullExtension.cs
- ServiceDescriptionContext.cs
- BinaryObjectReader.cs
- PersonalizationProviderCollection.cs
- DispatchRuntime.cs
- XmlLanguage.cs
- CompoundFileStreamReference.cs
- WsdlWriter.cs
- X509Extension.cs
- CrossSiteScriptingValidation.cs
- MetadataCache.cs
- BitmapPalette.cs
- CodeStatement.cs
- ThreadLocal.cs
- xsdvalidator.cs
- SoapFormatExtensions.cs
- XmlEncoding.cs
- StylusEditingBehavior.cs
- CatalogZone.cs
- TextBoxBaseDesigner.cs
- StringReader.cs
- Floater.cs
- Baml2006SchemaContext.cs