Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / whidbey / netfxsp / ndp / fx / src / Configuration / System / Configuration / KeyValueConfigurationCollection.cs / 1 / KeyValueConfigurationCollection.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System; using System.Xml; using System.Configuration; using System.Collections.Specialized; using System.Collections; using System.IO; using System.Text; [ConfigurationCollection(typeof(KeyValueConfigurationElement))] public class KeyValueConfigurationCollection : ConfigurationElementCollection { private static ConfigurationPropertyCollection _properties; static KeyValueConfigurationCollection() { // Property initialization _properties = new ConfigurationPropertyCollection(); } protected internal override ConfigurationPropertyCollection Properties { get { return _properties; } } // // Constructor // public KeyValueConfigurationCollection() : base(StringComparer.OrdinalIgnoreCase) { internalAddToEnd = true; } // // Accessors // protected override bool ThrowOnDuplicate { get { return false; } } public new KeyValueConfigurationElement this[string key] { get { return (KeyValueConfigurationElement)BaseGet(key); } #if DONT_COMPILE // if we ever expose this element this will be handy set { int index = -1; // append by default KeyValueConfigurationElement tempElement = (KeyValueConfigurationElement)BaseGet(key); if (tempElement != null) { index = BaseIndexOf(tempElement); BaseRemoveAt(index); } BaseAdd(index, value); } #endif } public String[] AllKeys { get { return StringUtil.ObjectArrayToStringArray(BaseGetAllKeys()); } } // // Methods // public void Add(KeyValueConfigurationElement keyValue) { // Need to initialize in order to get the key keyValue.Init(); // the appsettings add works more like a namevalue collection add in that it appends values // when add is called and teh key already exists. KeyValueConfigurationElement oldValue = (KeyValueConfigurationElement)BaseGet(keyValue.Key); if (oldValue == null) { BaseAdd(keyValue); } else { oldValue.Value += "," + keyValue.Value; int index = BaseIndexOf(oldValue); BaseRemoveAt(index); BaseAdd(index, oldValue); } } public void Add(String key, String value) { KeyValueConfigurationElement element = new KeyValueConfigurationElement(key, value); Add(element); } #if DONT_COMPILE public void Remove(KeyValueConfigurationElement keyValue) { if (BaseIndexOf(keyValue) >= 0) BaseRemove(keyValue.Key); } #endif public void Remove(string key) { BaseRemove(key); } public void Clear() { BaseClear(); } protected override ConfigurationElement CreateNewElement() { return new KeyValueConfigurationElement(); } protected override object GetElementKey(ConfigurationElement element) { return ((KeyValueConfigurationElement)element).Key; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System; using System.Xml; using System.Configuration; using System.Collections.Specialized; using System.Collections; using System.IO; using System.Text; [ConfigurationCollection(typeof(KeyValueConfigurationElement))] public class KeyValueConfigurationCollection : ConfigurationElementCollection { private static ConfigurationPropertyCollection _properties; static KeyValueConfigurationCollection() { // Property initialization _properties = new ConfigurationPropertyCollection(); } protected internal override ConfigurationPropertyCollection Properties { get { return _properties; } } // // Constructor // public KeyValueConfigurationCollection() : base(StringComparer.OrdinalIgnoreCase) { internalAddToEnd = true; } // // Accessors // protected override bool ThrowOnDuplicate { get { return false; } } public new KeyValueConfigurationElement this[string key] { get { return (KeyValueConfigurationElement)BaseGet(key); } #if DONT_COMPILE // if we ever expose this element this will be handy set { int index = -1; // append by default KeyValueConfigurationElement tempElement = (KeyValueConfigurationElement)BaseGet(key); if (tempElement != null) { index = BaseIndexOf(tempElement); BaseRemoveAt(index); } BaseAdd(index, value); } #endif } public String[] AllKeys { get { return StringUtil.ObjectArrayToStringArray(BaseGetAllKeys()); } } // // Methods // public void Add(KeyValueConfigurationElement keyValue) { // Need to initialize in order to get the key keyValue.Init(); // the appsettings add works more like a namevalue collection add in that it appends values // when add is called and teh key already exists. KeyValueConfigurationElement oldValue = (KeyValueConfigurationElement)BaseGet(keyValue.Key); if (oldValue == null) { BaseAdd(keyValue); } else { oldValue.Value += "," + keyValue.Value; int index = BaseIndexOf(oldValue); BaseRemoveAt(index); BaseAdd(index, oldValue); } } public void Add(String key, String value) { KeyValueConfigurationElement element = new KeyValueConfigurationElement(key, value); Add(element); } #if DONT_COMPILE public void Remove(KeyValueConfigurationElement keyValue) { if (BaseIndexOf(keyValue) >= 0) BaseRemove(keyValue.Key); } #endif public void Remove(string key) { BaseRemove(key); } public void Clear() { BaseClear(); } protected override ConfigurationElement CreateNewElement() { return new KeyValueConfigurationElement(); } protected override object GetElementKey(ConfigurationElement element) { return ((KeyValueConfigurationElement)element).Key; } } } // 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
- ObjectListFieldsPage.cs
- KerberosSecurityTokenProvider.cs
- Span.cs
- DeclaredTypeValidatorAttribute.cs
- BitmapCodecInfo.cs
- GcSettings.cs
- ContextToken.cs
- Trigger.cs
- RelationshipDetailsCollection.cs
- RegionIterator.cs
- ProfileInfo.cs
- DiagnosticTrace.cs
- SharedDp.cs
- URL.cs
- DesignSurface.cs
- Rights.cs
- FormViewDeletedEventArgs.cs
- PartialClassGenerationTaskInternal.cs
- Guid.cs
- CollectionViewGroup.cs
- GiveFeedbackEvent.cs
- PanelDesigner.cs
- WeakHashtable.cs
- QilReplaceVisitor.cs
- EncodingStreamWrapper.cs
- ToolTip.cs
- ConfigUtil.cs
- TableProviderWrapper.cs
- MethodAccessException.cs
- SchemaExporter.cs
- TextFormatterImp.cs
- IPHostEntry.cs
- MemberAccessException.cs
- ToolStripMenuItemCodeDomSerializer.cs
- ObjectItemCollection.cs
- CmsUtils.cs
- ItemsControl.cs
- CompatibleComparer.cs
- DynamicEndpoint.cs
- HMACSHA256.cs
- FormsAuthenticationTicket.cs
- VisualBrush.cs
- FormsAuthenticationConfiguration.cs
- SmtpMail.cs
- DbFunctionCommandTree.cs
- ResourceProviderFactory.cs
- Ticks.cs
- Misc.cs
- XmlSchemaRedefine.cs
- DataGridItem.cs
- MetaForeignKeyColumn.cs
- StringHelper.cs
- GeneralTransform3D.cs
- Cursor.cs
- DrawingCollection.cs
- IsolationInterop.cs
- TypefaceMetricsCache.cs
- WSDualHttpSecurityMode.cs
- WmiInstallComponent.cs
- PerspectiveCamera.cs
- PrimarySelectionGlyph.cs
- IteratorFilter.cs
- ScriptMethodAttribute.cs
- BitmapEffectDrawingContextState.cs
- TextServicesProperty.cs
- BroadcastEventHelper.cs
- SqlCacheDependencySection.cs
- AttributeAction.cs
- FieldAccessException.cs
- VisualBrush.cs
- PersonalizationDictionary.cs
- SharedConnectionInfo.cs
- WebPart.cs
- GeneralTransformCollection.cs
- XmlNode.cs
- NumericUpDownAcceleration.cs
- TextTreeTextBlock.cs
- PropertyValueUIItem.cs
- HtmlTitle.cs
- BufferedGraphicsManager.cs
- StorageAssociationSetMapping.cs
- AssemblyInfo.cs
- PolyLineSegment.cs
- TrustManager.cs
- Vector3DAnimationBase.cs
- PersistenceMetadataNamespace.cs
- SystemIPv6InterfaceProperties.cs
- XmlAnyAttributeAttribute.cs
- RelatedPropertyManager.cs
- StoreItemCollection.cs
- Wizard.cs
- PeerApplicationLaunchInfo.cs
- WeakRefEnumerator.cs
- Completion.cs
- QuaternionAnimation.cs
- SkipQueryOptionExpression.cs
- FlowDecisionDesigner.xaml.cs
- StringValidator.cs
- UIElementIsland.cs
- DynamicRendererThreadManager.cs