Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / 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
- UserInitiatedNavigationPermission.cs
- WebPartMenuStyle.cs
- PermissionToken.cs
- TailCallAnalyzer.cs
- DebugManager.cs
- AnnouncementDispatcherAsyncResult.cs
- SlipBehavior.cs
- TagPrefixInfo.cs
- ViewBase.cs
- precedingquery.cs
- EmissiveMaterial.cs
- ComplexTypeEmitter.cs
- ImageListStreamer.cs
- AssertValidation.cs
- HashHelper.cs
- XPathItem.cs
- BitVector32.cs
- ExpandCollapseProviderWrapper.cs
- PageCatalogPart.cs
- MetafileHeaderWmf.cs
- ExceptionUtility.cs
- PageMediaSize.cs
- ResourceReader.cs
- LinqDataSourceSelectEventArgs.cs
- DynamicFilterExpression.cs
- SynchronizationScope.cs
- ActivationServices.cs
- DragAssistanceManager.cs
- ContextStaticAttribute.cs
- SqlDataSourceEnumerator.cs
- SQLMoneyStorage.cs
- DeferredTextReference.cs
- ServiceThrottlingBehavior.cs
- SymbolPair.cs
- TableColumnCollectionInternal.cs
- QilXmlWriter.cs
- WebPartConnection.cs
- _BasicClient.cs
- ArglessEventHandlerProxy.cs
- _NegotiateClient.cs
- FilteredDataSetHelper.cs
- RuntimeEnvironment.cs
- DataGridViewCellConverter.cs
- SchemaLookupTable.cs
- LazyLoadBehavior.cs
- RestHandler.cs
- ImmComposition.cs
- XamlPointCollectionSerializer.cs
- XmlSerializerVersionAttribute.cs
- CheckBox.cs
- TextMetrics.cs
- XmlDocumentType.cs
- TreeNodeBindingCollection.cs
- DataBoundControlAdapter.cs
- FontSizeConverter.cs
- ControlCodeDomSerializer.cs
- PaintEvent.cs
- HttpCapabilitiesSectionHandler.cs
- CannotUnloadAppDomainException.cs
- TreeNodeEventArgs.cs
- HtmlElementEventArgs.cs
- _ListenerResponseStream.cs
- ClonableStack.cs
- LoginView.cs
- EnumMember.cs
- ExtentKey.cs
- ColumnResizeAdorner.cs
- DiscoveryClientBindingElement.cs
- UnmanagedMemoryStream.cs
- Viewport3DVisual.cs
- ClientRuntimeConfig.cs
- BaseResourcesBuildProvider.cs
- ZipIOCentralDirectoryDigitalSignature.cs
- NestPullup.cs
- GeneralTransform3DTo2DTo3D.cs
- HelpProvider.cs
- FixedSOMLineRanges.cs
- HttpPostClientProtocol.cs
- CompilerHelpers.cs
- SystemResourceHost.cs
- XmlValueConverter.cs
- PersianCalendar.cs
- DllNotFoundException.cs
- EdmProviderManifest.cs
- PtsContext.cs
- TrustManagerPromptUI.cs
- EventWaitHandleSecurity.cs
- WebHttpElement.cs
- Operand.cs
- IconConverter.cs
- QueryOptionExpression.cs
- MemberAssignment.cs
- RectangleHotSpot.cs
- BamlTreeNode.cs
- ContextDataSourceView.cs
- StorageMappingItemCollection.cs
- WindowsProgressbar.cs
- SqlExpressionNullability.cs
- BackStopAuthenticationModule.cs
- MenuCommand.cs