Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / 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
- SqlBulkCopyColumnMapping.cs
- EventLog.cs
- SelectionWordBreaker.cs
- DesigntimeLicenseContextSerializer.cs
- SizeConverter.cs
- ProtocolsConfigurationEntry.cs
- FullTextState.cs
- IndexedGlyphRun.cs
- Int32Animation.cs
- TextLineBreak.cs
- DataReaderContainer.cs
- PackagingUtilities.cs
- PublisherIdentityPermission.cs
- AutomationPatternInfo.cs
- InputBinding.cs
- HashJoinQueryOperatorEnumerator.cs
- FormsAuthenticationConfiguration.cs
- HashCodeCombiner.cs
- NotifyParentPropertyAttribute.cs
- AuthorizationContext.cs
- IndexedString.cs
- ObjectSecurity.cs
- DataGrid.cs
- StrokeNode.cs
- TrackingMemoryStream.cs
- SystemIPAddressInformation.cs
- CurrencyManager.cs
- SoundPlayerAction.cs
- SQLBytes.cs
- SimpleTypeResolver.cs
- CustomErrorsSection.cs
- InfiniteTimeSpanConverter.cs
- TransformedBitmap.cs
- DesignerOptionService.cs
- SslStream.cs
- ImageFormatConverter.cs
- XPathNavigator.cs
- MailMessageEventArgs.cs
- TextAction.cs
- TextElement.cs
- MetadataArtifactLoaderXmlReaderWrapper.cs
- XmlNodeList.cs
- PhysicalOps.cs
- ToolboxItemAttribute.cs
- RoleManagerSection.cs
- TCPListener.cs
- FontNamesConverter.cs
- NeutralResourcesLanguageAttribute.cs
- documentsequencetextview.cs
- StorageMappingItemLoader.cs
- EmptyStringExpandableObjectConverter.cs
- MembershipUser.cs
- ConsoleCancelEventArgs.cs
- XmlTypeMapping.cs
- AnnouncementEndpointElement.cs
- DataTableReaderListener.cs
- Int32AnimationUsingKeyFrames.cs
- UnwrappedTypesXmlSerializerManager.cs
- StrongNameIdentityPermission.cs
- XPathException.cs
- Animatable.cs
- ObjectItemCachedAssemblyLoader.cs
- ReflectEventDescriptor.cs
- ExistsInCollection.cs
- ToolBarPanel.cs
- ControlIdConverter.cs
- RoleServiceManager.cs
- ProcessProtocolHandler.cs
- XmlDocumentFieldSchema.cs
- SafeMarshalContext.cs
- CombinedGeometry.cs
- ManageRequest.cs
- CheckableControlBaseAdapter.cs
- CodePropertyReferenceExpression.cs
- HtmlElementEventArgs.cs
- CatalogZoneBase.cs
- StringWriter.cs
- AnnotationHelper.cs
- QilLoop.cs
- WpfWebRequestHelper.cs
- WebPartConnectionsCloseVerb.cs
- FatalException.cs
- sqlnorm.cs
- BoundPropertyEntry.cs
- DataObjectPastingEventArgs.cs
- CodeVariableDeclarationStatement.cs
- LocalTransaction.cs
- DateTimeOffsetAdapter.cs
- PriorityBindingExpression.cs
- MemberDomainMap.cs
- DesignerAutoFormatCollection.cs
- TypeListConverter.cs
- StructuralType.cs
- UICuesEvent.cs
- ToolStripStatusLabel.cs
- ParsedAttributeCollection.cs
- TextDecorationCollection.cs
- ProcessThreadCollection.cs
- FormViewUpdatedEventArgs.cs
- UnaryNode.cs