Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / KeyValueConfigurationCollection.cs / 1305376 / 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
- DataGridViewTopLeftHeaderCell.cs
- HttpRequest.cs
- EventPrivateKey.cs
- DesignerSerializationVisibilityAttribute.cs
- HtmlLink.cs
- Unit.cs
- Internal.cs
- Constraint.cs
- PlanCompilerUtil.cs
- RedirectionProxy.cs
- CommandEventArgs.cs
- WebProxyScriptElement.cs
- TreeIterator.cs
- RawAppCommandInputReport.cs
- PersonalizableAttribute.cs
- MetaModel.cs
- GZipDecoder.cs
- BitmapMetadataBlob.cs
- ScrollProperties.cs
- ForwardPositionQuery.cs
- CollectionContainer.cs
- CaretElement.cs
- PropertyGroupDescription.cs
- HttpResponseHeader.cs
- ActiveXSite.cs
- MostlySingletonList.cs
- FunctionUpdateCommand.cs
- ProviderBase.cs
- HashStream.cs
- DynamicILGenerator.cs
- StrongNameKeyPair.cs
- Compress.cs
- dataprotectionpermissionattribute.cs
- RegexWorker.cs
- NonceToken.cs
- TypeConverterAttribute.cs
- SystemColors.cs
- HyperLinkColumn.cs
- SystemInfo.cs
- IncrementalHitTester.cs
- ObjectParameterCollection.cs
- DynamicFilter.cs
- CustomAttributeFormatException.cs
- ObjectSpanRewriter.cs
- COM2DataTypeToManagedDataTypeConverter.cs
- _ScatterGatherBuffers.cs
- RuntimeCompatibilityAttribute.cs
- ExpandoObject.cs
- HwndSourceParameters.cs
- PartitionedStreamMerger.cs
- GetPageCompletedEventArgs.cs
- MessagePropertyDescription.cs
- AtlasWeb.Designer.cs
- ResourcesBuildProvider.cs
- RawStylusInputReport.cs
- WebHttpSecurityElement.cs
- FrameworkTextComposition.cs
- Models.cs
- DBBindings.cs
- uribuilder.cs
- CompositeTypefaceMetrics.cs
- RectKeyFrameCollection.cs
- ResourceKey.cs
- streamingZipPartStream.cs
- DataBoundControlAdapter.cs
- EventRoute.cs
- KnownTypeDataContractResolver.cs
- XPathNodeHelper.cs
- RangeExpression.cs
- OleDbDataAdapter.cs
- WorkflowShape.cs
- DragEvent.cs
- _SslStream.cs
- BitmapEffectRenderDataResource.cs
- XmlAttributes.cs
- ManualWorkflowSchedulerService.cs
- SingleAnimationUsingKeyFrames.cs
- Message.cs
- HttpException.cs
- MergablePropertyAttribute.cs
- BridgeDataRecord.cs
- SettingsProviderCollection.cs
- TranslateTransform.cs
- SimpleColumnProvider.cs
- MenuCommands.cs
- WindowExtensionMethods.cs
- cache.cs
- UInt64Converter.cs
- SoapDocumentMethodAttribute.cs
- WebPartCloseVerb.cs
- ObjectStateManagerMetadata.cs
- TaskFileService.cs
- OracleRowUpdatedEventArgs.cs
- SqlFunctionAttribute.cs
- UriTemplate.cs
- EmptyStringExpandableObjectConverter.cs
- SqlGenericUtil.cs
- LayoutTable.cs
- TypedReference.cs
- CheckBoxPopupAdapter.cs